You are familiar with addition and subtraction operations. George Boole discoved that
similar operations could be used to describe logical thinking. His work is the theoretical basis
of all digital circutry and computers.
Learn the three Boolean operators: && (and), ||(or), and !(not).
Note -- until I mastered Boolean Algebra my programs tended to be full
of stupid errors. People would laugh at my code....
You can use the words "and", "or", "not" in place of "&&", "||", "!" if you wish
You rarely need to output or input Boolean values. An exception is when
you want to print out a truth table.
First you should add "#include <iomanip>" to the header files listed before the program starts.
Second you indlude the input-output manipulator "boolalpha" before you first attempt to
"cout" a boolean --- this means that instead of outputting "1" or "0" the program will
output "true" or "false". Third, the expression is put in parentheses -- the compiler
treats boolean operators as a lower priority than the "<<" operator... So you end up with
cout << boolalpha << (p && !q && r) << ...
[ printBool.cpp ]
is an example program showing a bool being output before and after
the boolalpha manipulator has been used.
You never ask a user to supply "true" or "false" in real programs! It is better to ask a "Yes/No" question
and accept "yes"/"no". Then you can convert the sting into a bool variable. For example:
cout << "Are you male (y/n)? );
cin >> input;
bool male = ( input.substr(0,1) == "y" );
This allows people to input "y", "yes", "yep",.... etc.
How many ways can you write code like the above to allow the user to respond "Y", "Yes", "YES", ... ?
[ george2.cpp ]
if( a or b == 1)....
when you need
if( (a==1) or (b==1) ) ...
This topic is too important for sorting out complex conditions fo you to put it off.
What do you think is "intelligence"?