LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   an if statement that has two variables (https://www.linuxquestions.org/questions/programming-9/an-if-statement-that-has-two-variables-369699/)

mshinska 10-04-2005 10:56 AM

an if statement that has two variables
 
i am working in c++ and i need to make an if statement that says if a and b are equivelent to 0 then...

the only way that I could think of was
if (a==0) (b==0)
{...
}

this however does not work.

thanks for all your help!

paulsm4 10-04-2005 10:58 AM

Code:

if ( (a==0) && (b==0) )
{
  ...
}

Equivalently:
Code:

if ( (!a) && (!b) )
{
  ...
}

PS:
I'd really discourage you from putting code after your start ("{") brace:
http://www.gnu.org/prep/standards/
http://geosoft.no/development/cppstyle.html
http://www.chris-lott.org/resources/cstyle/
etc etc ad nauseum...

PPS:
Here are the two variants you'll see most often: I'd choose one of these:
Code:

// K & R, Java:
  if (x == y) {
    << do something >>
  }


Code:

// ANSI C/C++, .Net:
  if (x == y)
  {
    << do something >>
  }



All times are GMT -5. The time now is 06:12 PM.