GUESSING GAME (C language)Assignment Outcomes:1. To develop skills in using the selection constructs (if, and ifelse).2. Use the iteration constructs (while, do, for).3. Use Boolean variables and expressions to controliterations.4. Random number generation.5. Good Design techniquesRequirements:1) Develop a simple number guessing game. The game is played by theprogramrandomly generating a number and the user attempting to guess thatnumber. Aftereach guess the program will provide a hint to the user identifyingthe relationshipbetween the number and the guess. If the guess is above the answerthen “Too High”is returned, if the guess is below the answer then “Too Low”. Alsoif the differencebetween the answer and the guess is less than the differencebetween the answer andthe previous guess, “Getting warmer” is returned. If the differencebetween theanswer and the guess is more than the difference between the answerand the previousguess, then “Getting Colder” is returned.2) The program will allow the user to play multiple games. Once agame is complete theuser will be prompted to play a new game or quit.3) Basicsa. variables.i. answer - an integer representing the randomly generatednumber.ii. gameOver – a Boolean, false if game still in progress, true ifthe gameis over.iii. differential – an integer representing the difference betweena guessand the answer.iv. max – maximum value of the number to guess. For example, ifthemaximum number is 100 then the number to guess would bebetween0 and 100. (inclusive)v. maxGuessesAllowed – the maximum number of guesses the usergets,once this value is passed the game is over.vi. numGuessesTaken – an integer that stores the number ofguessedtaken so far in any game
b. Functionsi. newGame function1. Takes in an integer as a parameter representing themaximumnumber of guesses and sets maxGuessesAllowed . In otherwords the parameter represents how many guesses the user getsbefore the game is over.2. Generates the answer using the random number generator. (0-max).3. Sets gameOver to false.4. Sets differential to the max value.5. Sets numGuessTaken to zero.ii. guess method1. Takes in an integer as a parameter representing a newguess.2. Compares the new guess with the answer and generates andprints representing an appropriate response.3. The response is based on:a. The relation of the guess and answer (too high, too lowor correct).b. The comparison of difference between the currentguess and the answer and the previous guess and theanswer. (warmer, colder)c. Guess out of range error, if the guess is not between 0and the max number (inclusive)d. User has taken too many guesses becausenumGuessesTaken is greater than maxGuessesAllowed.If this is the case set isGameOver to true.iii. isGameOver method - returns the state of game.1. true if game is over2. false if still in progress.
Sample Output:Welcome to the Guessing GameEnter the maximum number100answer is: 8 (Included for testing only, should not be display infinal program)Enter the number of guesses allowed:6Enter your guess, remember it must be between 0 and 10050Too HighGetting WarmerEnter your guess, remember it must be between 0 and 10025
Too HighGetting WarmerEnter your guess, remember it must be between 0 and 10012Too HighGetting WarmerEnter your guess, remember it must be between 0 and 1006Too lowGetting WarmerEnter your guess, remember it must be between 0 and 1008CongratulationWould you like to play again, enter Y for yes, N for no.y
Welcome to the Guessing GameEnter the maximum number50answer is: 36Enter the number of guess allowed:5Enter your guess, remember it must be between 0 and 5060Guess out of range, The guess must be between 0 and 50Enter your guess, remember it must be between 0 and 5025Too lowGetting WarmerEnter your guess, remember it must be between 0 and 5048Too HighGetting ColderEnter your guess, remember it must be between 0 and 5037Too HighGetting WarmerEnter your guess, remember it must be between 0 and 5036CongratulationWould you like to play again, enter Y for yes, N for no.screenshot of your running program
GUESSING GAME (C language) Assignment Outcomes: 1. To develop skills in using the selection constructs (if, and if else)
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am