Mini Assignment – Guessing Game

The Assignment:

Create a simple number Guessing Game. The computer randomly selects a number between one and 100. The user enters a guess. The computer tells the user whether the guess is too high, too low or correct. The computer should record the number of guesses that it takes the user. It should also give the user the option to play again. The code for generating a random number is:

For this assignment you will need to use random numbers. Here is the code:

   get a secret number
   get the user's guess
   while(the guess doesn't equal the secret number)
   {    if (the guess is higher than the secret number)
            print too high
        else if (the guess is lower than the secret number)
            print too low
       get the user's next guess
   }
   print Congradulations, you got it!

All programming assignments should:

T h e G u e s s i n g G a m e

The computer has picked a number between 1 and 100.

What is your #1 guess? 50

That is too high.

What is your #2 guess? 25

That is too low.

What is your #3 guess? 37

That is too high.

What is your #4 guess? 30

That is too high.

What is your #5 guess? 27

That is correct! You got the answer in 5 guesses.

Would you like to play again? (y/n) y

The computer has picked a number between 1 and 100.

What is your #1 guess? 50

That is too low.

What is your #2 guess? 75

That is too low.

What is your #3 guess? 87

That is too low.

What is your #4 guess? 95

That is correct! You got the answer in 4 guesses.

Would you like to play again? (y/n) n

Good bye! Thanks for playing.