< Previous | Contents | Next >

Interpreting a Value as true or false

You can interpret any value as true or false. Any non-zero value can be interpreted as true, while 0 can be interpreted as false. I put this to the test in the next if statement:

if (score)

{

cout << "At least you didn’t score zero.\n\n";

}

score is 1000, so its non-zero and interpreted as true. As a result, the message,

Okay, at least you didnt score zero,is displayed.

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