![]() |
Example 18We'd like now to extend the design of the previous program and add one or two new features. It would be helpful if the program could give some clues and say whether the guess is too big or too small. It would also be helpful if the program could count the number of guesses and print the total at the end. We'll start our new design just like the original one: 1. Design a Solution 1. get number from player 1
Step 1 becomes: 1.1 prompt player 1 for number
Step 3 becomes: 2.1 repeat
Step 2.4 needs some clarification - note how the numbering system works... 2.4.1 if guess > number
Step 3 becomes: 3.1 print message
So the complete solution is:
|
1.1 prompt player 1 for number
2.1 repeat
3.1 print message
|
2. Code the Program As before, you should note that the whole point of designing the program is to make it easy to code. Check that the design above corresponds with the program below.
|
PROGRAM guessing; {a guessing game} VAR
BEGIN
REPEAT
IF guess > number
WRITELN('well done');
|
This completes Part 1 of the tutorial, so well done if you've followed everything so far.
|
© 1998 John Brewer |