/*
Working with boolean logic.
See Nyhoff P111-116.
==, !=, < , >, <=, >= are relational operators for integers and doubles that produce boolean expressions.
&& , || , ! are logical operators for boolean variables. Do not confuse these with bitwize operations!
&& (and) has higher precedence than || (or), just like * has higher precedence than +.
1) What is numbers are printed out at WTF?
2) Run the program with some numbers to check if it works.
*/
#include
using namespace std;
int main()
{
int number=42;
bool isEven = number%2==0;
bool isNegative = number<0;
bool isZero = number==0;
bool isnonZero = number!=0;
if (isEven) cout << number << " is even\n";
if (isNegative) cout << number << " is negative\n";
if (isEven && isNegative) cout << number << " is even AND negative\n";
if (isEven || isNegative) cout << number << " is even OR negative\n";
if (!isNegative) cout << number << " is NOT negative i.e. it is positive\n";
// WTF
if (isEven && !isNegative || isZero) cout << number << " is < ??? >\n";
return 0;
}