4.3. if Selection Statement
Programs use selection statements to choose among alternative courses of action. For example, suppose the passing grade on an exam is 60. The statement
if ( grade >= 60 ) cout << "Passed";
determines whether the condition grade >= 60 is
false. If the condition is
"Passed" is printed and the next statement in order is performed. If the condition is
false, the output statement is ignored and the next statement in order is performed. The indentation of the second line is optional, but it’s recommended because it emphasizes the inherent structure of the program.
It’s important to note here that we’re casually assuming that
grade contains a valid value—an integer in the range 0 to 100. Throughout the ...