< Previous | Contents | Next >

Introducing Guess My Number

The final project for this chapter, Guess My Number, is the classic number- guessing game. For those who missed out on this game in their childhood, it goes like this: The computer chooses a random number between 1 and 100, and the player tries to guess the number in as few attempts as possible. Each time the player enters a guess, the computer tells him whether the guess is too high, too low, or right on the money. Once the player guesses the number, the game is over. Figure 2.14 shows Guess My Number in action. You can download the code for this program from the Course Technology website (www.courseptr. com/downloads). The program is in the Chapter 2 folder; the filename is guess_my_number.cpp.

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



image

Figure 2.14

I guessed the computer’s number in just three tries.


 

Applying the Game LoopSetting Up the GameCreating the Game LoopWrapping Up the Game