0

Why does this operation equal true even though it should have no output because its false because true + false = false?

int age = 42; int money = 4; if (age > 21 && money > 500) { cout << "Welcome" << endl; }

12/2/2016 4:57:31 AM

Dustin Boudreaux

3 Answers

New Answer

+2

I tried this code and I have no output, maybe it is a bug for you. If you want, you can try this on the 'if' statement instead : if ( (age > 21) && (money > 500) ) It is no different from what you wrote before, but maybe can help to solve the problem for you because sometimes programming tools are a little bit faulty.

+1

In this if condition, you're using logical AND operator, which means both conditions should be true then only IF block will execute. If anyone of the condition false then IF block won't execute. Please note that AND is not equal to addition. Change && to || (logical OR) then it will behave like you expected. Basically OR operator is behaves like addition. Hope you understand well.

0

true dat and thanks