CSCI 150, Spring 2003
Home | | Course Schedule | | Assignments | | Lecture NotesDue Friday, February 14, at the beginning of class.
Goals
The goals of this assignment include:
The quizmaster chooses a number, and the guesser attempts to guess it. After each guess, the quizmaster responds with one of three responses:
(Of course the number in the response, 5 in this example, varies, depending on the number of guesses the guesser actually made.) Here is a sample session.Your guess is high. Your guess is low. Your guess is correct. You made 5 guesses altogether.
C:\>highlow I am thinking of a number between 0 and 20. Take a guess. 1 Your guess is low. Take a guess. 13 Your guess is high. Take a guess. 7 Your guess is low. Take a guess. 11 Your guess is correct. You made 4 guesses altogether. Thanks for playing High/Low. C:\>
The quizmaster chooses a number at the beginning of the game, and doesn't change it. All the numbers are integers. The various answers the quizmaster gives must all be correct, as must the announced range. The chosen number may be at either extreme of the announced range, for example number of 20 is legal for the range between 1 and 20. The quizmaster may change ranges for each game, but is not required to do so.
Guesser
The guesser should only answer with integer numbers; for example the answer 'one' is not a legal guess. The guesser's goal is to minimize the number of guesses, so although a strategy of counting through the range is perfectly legal, it is not the best plan. The guesser may repeat guesses, even though there is no point to doing so, or may guess numbers outside the range. The responses to such silly guesses are the same as for other high or low guesses.
One way to choose a number in Pascal is used in the sample program that follows
program choose; {Author: A. Professor Section: CSCI 150, MTR Date: October 8, 2002 Purpose: illustrate random() function.} var num: integer; begin randomize; {This line "shuffles" the choices -- } { otherwise they're the same every time.} num := random(21); {This makes the choice. num will be between 0 and 20} writeln('I choose ', num); {Here we put it on the screen to show that} {the choice scheme works.} end.
I want you to have a while loop which includes statements to handle a single guess. Each guess the user makes should go through the loop again.