How do I say not equal to more than one number?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abrown07
    New Member
    • Jan 2010
    • 27

    How do I say not equal to more than one number?

    I am trying to say if( my variable is not equal to 1 or 2)

    I would write

    if(variable != 1 ) but I do not know how to say or 2 in programming language?
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    You don't want to say "or". You want
    (variable != 1) and (variable != 2)
    So the question is, what is the operator for logical-and?

    Comment

    • abrown07
      New Member
      • Jan 2010
      • 27

      #3
      im using gcc for mac , so how would i format that to say and?

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Look in an C/C++ book or online reference for the operators or just google "C++ operators".

        All the operators are a basic part of the language and you should know about them if you are going to program in C/C++

        Comment

        • DEAbhishekBUG
          New Member
          • Feb 2010
          • 3

          #5
          See if u want to write
          1> if given variable is either not equal to 1 or 2 you need to code:
          if((variable !=1)||(variable !=2)) // ' | '(just above enter key ) :is called as pipeline operator and is logical equivalent of " or "

          2>if given variable is not eqal to both 1 & 2 :
          if((variable !=1)&&(variable !=2)) // ' & ' :is and operator
          if this is not what u r looking for please ask questions

          Comment

          • donbock
            Recognized Expert Top Contributor
            • Mar 2008
            • 2427

            #6
            Originally posted by DEAbhishekBUG
            1> if given variable is either not equal to 1 or 2 you need to code:
            if((variable !=1)||(variable !=2)) // ' | '(just above enter key ) :is called as pipeline operator and is logical equivalent of " or "
            This expression is not very useful -- it is always true.

            Comment

            Working...