Guess what? You already have the whole program (in English) staring you in the face. Well, maybe not. Recall that I said four pages ago that I would start off telling the other person what the Guessing Game does. I said
Hi. We are going to play the Guessing Game.That is a good English description of the program. It is the program, in a loosey-goosey way. Now let's you and me tighten it up some, mostly that second line. It will still be English, but let's describe more carefully what the computer will be doing:
You think of a number, then I will ask some yes/no questions,
then I will tell you what number you thought of.
Are you ready?
iterateYou see, this is still English, and still pretty vague, but a lot more precise than what I started out with. In particular, I changed a vague word "some" with a more detailed use of one of the Five Concepts. Also I put it in a table-like form, so it's easier to see what gets repeated (iterated, looped, same idea). Remember, when we tell the computer to "repeat" or "iterate" we are telling the computer that we are giving it a list of things to do, and it should do them over and over, several times, until it's time to stop. We humans still think of doing them all in one straight line, and the computer will do them in one straight line, but writing those steps over and over gets tiresome -- impossible if the number of repetitions is not known in advance -- so we tell the computer this is an iteration.
ask a question
input answer
next iteration
There. You have the whole program.
Actually, we are still in the design phase. Exactly what question is the computer going to ask? What question(s) would you ask, if you were the one doing the guessing? Think about what you would ask, not just the first question, but also the second, third, and fourth. How many questions do you need to ask before you know what number they thought of? Think about that for a while, then turn the page.
Five Basic Concepts Sequence Iteration Conditional Variables Input/Output
<<Previous | ToC | Next >>
[2021 July 12]