next up previous contents
Next: Hint Up: Array Related Algorithms Previous: Sorting   Contents


Homework Assignment

In this assignment, the computer plays the game of number guessing using binary search technique. In other words, the following is a scenario of a game play:

I have 6 guesses, is it 25?
-1
I have 5 guesses, is it 12?
1
I have 4 guesses, is it 18?
1
I have 3 guesses, is it 21?
-1
I have 2 guesses, is it 19?
0
I guessed the number in 5 guesses.

In this program, the computer needs to keep track the number of guesses remaining (starting with 6) and use the binary search technique to guess a number between 0 and 50. After the computer presents a guess, the user can answer with -1 if the guess is too little, 0 if the guess is correct and 1 if the guess is too large.

The program needs to indicate that the user is cheating if the user inputs inconsistent hints.



Subsections

Tak Auyeung 2003-12-03