You are using a version without Ads of this website. Please, consider donating:

### How to do this if not this

 ``1234567891011121314`` `````` //Check if one number is 0 if(numerator1>0){ if(denominator1>0){ if(numerator2>0){ if(denominator2){ cout << "There is no unknown variable."; } } } } //Output answer, if one variable is 0 cout << "Your unknown variable is " << answer << "!";``````

That is some code to my proportion calculator. Normally, it would output the answer. But I said that if all the numbers are less than 0(I use that as the unknown variable) that it will output there is no variable.

It does say "there is no variable" if there is none. However it will output the answer(0).

There is no unknown variable.Your unknown variable is 0!

How do I do a "if not this, this" statement?
if-else-clause
 ``12345678`` ``````if ( cond ) { statement; } else { statement; }``````

"logical and" operator (&&)
 ``12`` ``````condA && condB (0 < numerator1) && (0 < denominator1)``````

If (numerator1 == 0) && numerator2 == 0 && denominator2 == 0) cout <<"There is no unknown variable";

or (more logically)

if (numerator1 != 0) cout<<"Your unknown variable is "<<numerator1;
else if (numerator2 != 0) cout<<"Your unknown variable is "<<numerator2;
else if (denominator != 0) cout<<"Your unknown variable is "<<denominator2;
else cout<<"There is no variable.";

Assuming you wanted it to check if denominator 2 is equal to zero, you didn't specify a statement or condition in the if statement.
Last edited on
Topic archived. No new replies allowed.