Number guessing game

I am a student studying computer science and I have this as first assignment, the computer as to make guesses for the secret number.
Hopefully someone can help me! :)

The Assignment

The game to play is a well known number guessing game. Alice asks Bob to pick a secret number between 1 and 15. When Bob has selected his number, Alice will guess it. If Alice's guess is correct Bob will respond “You win”. If his secret number is lower than Alice's guess, Bob will reply “lower”, and Alice will guess again. If his number if higher, he will respond “higher”, and Alice will guess again. If the number is correct, Bob will reply “You win”, Alice wins, and the game is over. If Alice does not find the correct number within 10 attempts, she gives up, and Bob wins.

The task is to write a program that plays for Alice. This means, your program will repeatedly guess Bob's secret number, print the guess to standard output, reads Bob's answer from standard input, and give up after 10 failed attempts
Last edited on
Use binary search algorithm. Start with 1 and 15, guess the first number as 8 (mid point of 1 and 15). You current range is 1-15. If the response is lower, make your new range as 1-7. if it is higher make it 8-15. Keep repeating the same procedure.
Write pseudocode and it should have the following;

1. It should write the guess of the secret number to standard output.
2. It should ask the user if the secret number is higher, lower, or if you guessed correctly.
3. It should read the answer. Repeat the question if it is not one of three possible answers.
4. It should claim victory if the answer is that the guess is correct.
5. It should keep asking until it has a correct guess, or give up after 10 failed attempts.
6. It should only accuse the player of cheating, if it is absolutely certain.
We won't complete your assignment for you.
You're a comp sci student and can't do that? That is one of the easiest starting assignments and they only get harder and more complex from there. If you can't do that then you are either over thinking it or should start considering a different major. We help with problems here, we don't do the problems.
Topic archived. No new replies allowed.