Skip to content

Instantly share code, notes, and snippets.

@rszewczyk
Last active November 9, 2017 21:12
Show Gist options
  • Save rszewczyk/831e742229e65cf42be2533ccc8c49da to your computer and use it in GitHub Desktop.
Save rszewczyk/831e742229e65cf42be2533ccc8c49da to your computer and use it in GitHub Desktop.
UMBC CMSC104 Project 2

Project 2

Due Tuesday 11/28/2017 at 5:30pm EST

Instructions

Write a program that allows two players to play a guessing game. The program works as follows:

  1. First, player 1 enters the secret number. The program should check that the number is not less than 0 and not greater than 99, prompting the user to re-enter the number if needed.
  2. Player 1 is then prompted for, and enters the number of guesses that player 2 gets.
  3. 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).
  4. 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.

Sample input/output for a loss:

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 :-(

Sample input/output for a win

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 :-)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment