The Guessing Game

Design First

In your program you have a sequence of steps. If you get the steps out of order, the message being spoken (or in the case of a computer, printed on the screen) doesn't make sense (or at least sounds goofy). And each of those steps is an output, something the computer says to the outside world -- in this case, you. Later on today you can show it to your friends and family.

The last thing the computer says (in my version, yours may be different) is "Are you ready?" That asks a question, and we normally expect an answer when we ask questions. That would be input, which shares the concept line with output in the list below. The question is a little vague, I guess maybe they could answer "Yes" that they are ready, or "No" because they don't like games. Let's not go there.

Then we need to invite them to think of a number (but don't tell us). And are they ready again with their number. Or we could assume they are ready to play, and just ask one question, have they thought of a number.

What if they think of a really huge number, like 59,365,784? Do you know how long it would take to guess that number? It wouldn't be fun any more. So let's set some limits, say between 1 and 99. Now we need to think of how we change that one output line to instead invite them to think of a number between 1 and 99.

Notice that in three paragraphs of thinking about your program, we have not written a single line, except to change one line that was already written. The most important part of programming is not writing the code, but design -- here the introductory remarks. We still have the main part of the program yet to be designed.

At least now we know what the program must do next. Why don't you add that one line, then turn the page.

Five Basic Concepts
Sequence
Iteration
Conditional
Variables
Input/Output

<<Previous | ToC | Next >>

[2021 April 19]