< Previous | Contents | Next >

Creating Two Ways to

Branch

Youve seen the first part of the if statement already, and it works just as it did before. If score is greater than 1000, the message, You scored 1000 or more. Impressive!is displayed.

48 Chapter 2 n Truth, Branching, and the Game Loop: Guess My Number


if (score >= 1000)

{

cout << "You scored 1000 or more. Impressive!\n";

}

Heres the twist. The else clause provides a statement for the program to branch to if the expression is false. So if (score >= 1000) is false, then the program skips the first message and instead displays the message, You scored less than 1000.

else

{

cout << "You scored less than 1000.\n";

}