![]() |
Example 14This is a game for two players. The program should ask one of the players to enter the name of a country and then the name of its capital. The screen is cleared and the program should then ask the other player to enter the capital of the country and print an appropriate message, depending on whether the answer is right or wrong. 1. Design a Solution Our first attempt looks like this: 1. get information from player 1
Step 1 becomes: 1.1 prompt player 1 for country
Step 2 becomes: 2.1 prompt player 2 for answer
Step 3 is the crucial one and becomes: 3.1 if answer is correct
So the complete design is:
|
1.1 prompt player 1 for country
2.1 prompt player 2 for answer
3.1 if answer is correct
|
2. Code the Program
|
PROGRAM quiz; {a quiz game} VAR
BEGIN
|
3. Test the Program
|
country | capital | answer | result |
France | Paris | Paris | correct |
France | Paris | paris | |
France | Paris | 77 | |
Venezuela | Caracas | Caracas | |
USA | Washington | Washington |
A summary of the results might be: "The program gave correct results when the answer matched the capital exactly - it is case-sensitive in as much as upper and lower case letters have to be the same. For example, "Paris" is not the same as "paris". If the user enters a number instead of some text then the answer will be wrong but it will not cause a 'run-time error'. If the text is longer than the string - eight characters, in this case - then the word is simply shortened to fill the space allowed." 4. Evaluate the Solution An evaluation of the program might be: "The program meets the design specification and produces correct results when tested. Many improvements are, however, possible. An obvious one would be so that the user could use either upper or lower case letters - provided, of course, that the spelling was correct. The program could be developed such that a number of questions were asked and the user could then be given a score."
|
© 1998 John Brewer |