Write a program that allows two players to play a guessing game. The program works as follows:
- First, player 1 enters the secret number. The program should check that the number is
not less than 0
andnot greater than 99
, prompting the user to re-enter the number if needed. - Player 1 is then prompted for, and enters the number of guesses that player 2 gets.
- Player 2 begins entering guesses. The prompt for a guess should inform the user how many guesses they have remaining. After they make an incorrect guess, the program should tell them if their guess is greater than or less than the secret number and prompt for another guess (with an updated count of guesses remaining).
- If player 2 guesses the number before running out of guesses they win. The program should inform player 2 whether they won or lost.
Sample input/ouput for a couple of outcomes are below. Your input/output can vary slightly from this, but the functionality must be the same.
Save your work in a file called project2.c
and submit it to me on Slack.
Player 1: Type a number between 0 and 99 and press return (player 2, no peaking!): 101
Secret number cannot be greater than 99. Type a number between 0 and 99 and press return (player 2, no peaking!): 80
Type the number of guesses that player 2 gets and press return: 7
Player 2: Type your guess and press return (guesses remaining: 7): 14
Your guess was less than the secret number. Type your guess and press return (guesses remaining: 6): 81
Your guess was greater than the secret number. Type your guess and press return (guesses remaining: 5): 45
Your guess was less than the secret number. Type your guess and press return (guesses remaining: 4): 59
Your guess was less than the secret number. Type your guess and press return (guesses remaining: 3): 62
Your guess was less than the secret number. Type your guess and press return (guesses remaining: 2): 70
Your guess was less than the secret number. Type your guess and press return (guesses remaining: 1): 71
Your guess was less than the secret number.
Sorry you are out of guesses :-(
Player 1: Type a number between 0 and 99 and press return (player 2, no peaking!): 20
Type the number of guesses that player 2 gets and press return: 5
Player 2: Type your guess and press return (guesses remaining: 5): 50
Your guess was greater than the secret number. Type your guess and press return (guesses remaining: 4): 10
Your guess was less than the secret number. Type your guess and press return (guesses remaining: 3): 25
Your guess was greater than the secret number. Type your guess and press return (guesses remaining: 2): 19
Your guess was less than the secret number. Type your guess and press return (guesses remaining: 1): 20
You guessed the secret number :-)