Homework Two

Your assignment is to write a guessing game. You will need to use if and else for testing, and then add a loop to repeat the guessing process. I have broken down the process into several steps, so you can build the program a step at a time. Hand in a printout of your final program and a sample run.

  1. Write a program that asks the user to guess a secret number (you pick the number when you write the program). If the user guesses the number correctly, they win. If they don't guess correctly, they lose.

    Here's a sample run where the player loses. The input from the player is shown in bold, everything else is printed by the program.

    Welcome to the number guessing game.
    I'm thinking of a number between 1 and 10.
    Please enter your guess followed by a return: 6
    Sorry, the number was 3.
    

    Here's what happens if the player guesses the number:

    Welcome to the number guessing game.
    I'm thinking of a number between 1 and 10.
    Please enter your guess followed by a return: 3
    You guessed the secret number!
    
  2. Modify your program so the computer gives hints if the player does not guess the number correctly. If the player does not guess the secret number, they are either too high or too low. For example:

    Welcome to the number guessing game.
    I'm thinking of a number between 1 and 10.
    Please enter your guess followed by a return: 6
    6 is too high.
    Sorry, the number was 3.
    
  3. Modify your program so the user can guess repeatedly until they get the correct answer. For example:

    Welcome to the number guessing game.
    I'm thinking of a number between 1 and 10.
    Please enter your guess followed by a return: 6
    6 is too high.
    Please enter your guess followed by a return: 2
    2 is too low.
    Please enter your guess followed by a return: 5
    5 is too high.
    Please enter your guess followed by a return: 3
    You guessed the secret number!