Skip to content

Guess that Number

As a second example, let’s build a small guess that number program from the ground up. Now that you have functions and procedures, we can start by breaking the problem down before we think about the individual logic with each function and procedure.

Problem description

Table x.y contains a description of the next program we are going to design. This program plays a small guessing game called Guess that Number. In this game the computer will think of a target number between 1 and 100. The user then has 7 guesses to determine the target number’s value. At each guess the computer outputs a message to indicate if the target number is greater than, less than, or equal to the user’s guess.


NameGuess that Number
DescriptionA simple guessing game where the computer ‘thinks’ of a number between 1 and 100, and the user has seven guesses to guess it. With each guess the computer indicates if the number it is thinking of is less than, or greater than the user’s guess. If the user runs out of guesses they are shown the answer, and that round ends. After each round the user has the option to play again, or to quit the program.
Description of the Guess that Number program.

As before, the process to design and implement this program will follow a number of steps:

  1. Understand the problem, and get some ideas on the tasks that need to be performed.
  2. Choose the building blocks we will create and use.
  3. Design the control flow for each function and procedure.
  4. Map this logic to code
  5. Compile and run the program

The new step in this process will involve designing the flow of the instructions within the program, and the functions and procedures that need to be created.