What could be the logical error in the code snippet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gnanapoongothai
    New Member
    • Jun 2007
    • 62

    What could be the logical error in the code snippet

    what is logical error found in the code below .Could any find.


    Code:
    If( (x!=3)  || (x!=4) )
     printf("something");
    
    else 
      printf("something")
    thanks in advance for your answers.
  • Meetee
    Recognized Expert Contributor
    • Dec 2006
    • 928

    #2
    Originally posted by gnanapoongothai
    what is logical error found in the code below .Could any find.


    Code:
    If( (x!=3)  || (x!=4) )
     printf("something");
    
    else 
      printf("something")
    thanks in advance for your answers.
    I think there are syntax error:
    1) If instead of if
    2) ; missing after second printf

    Regards

    Comment

    • Shashi Sadasivan
      Recognized Expert Top Contributor
      • Aug 2007
      • 1435

      #3
      Originally posted by gnanapoongothai
      what is logical error found in the code below .Could any find.


      Code:
      If( (x!=3)  || (x!=4) )
       printf("something");
      
      else 
        printf("something")
      thanks in advance for your answers.
      I believe the If statement should be like
      If( (x!=3) && (x!=4) )

      with the OR operator it will be true for all values

      Comment

      Working...