新手问道题The Guessing Game
Problem 1: The Guessing GameYou want to play the Guessing Game, where one player has a secret number memorized and the other
player attempts to guess it in a fixed number of tries. In this version of the game, the number is always
between 0 and 1000, and the guesser is allowed 10 guesses to try to identify the number. After making a
guess, the guesser is told whether his guess was too high, too low, or spot on. The game ends when the
allowable guesses are exhausted or the number is identified.
a) What sort of data should be #defined in this program?
b) Write the function InRange, which takes a number and checks whether that number is between a lower and upper limit (both of which are parameters to the function)
boolInRange(intnumber,intlow,inthigh)
c) Write the function TakeAGuesswhich asks the user for a guess until it is in the specified range. It then returns TRUEif the guess is correct. If the guess is not correct, then it tells the user if he is too high or too low and returns FALSE. You should use InRangein your solution.
boolTakeAGuess(intnumber,intlow,inthigh)
d) Write the function PlayGamewhich calls TakeAGuessuntil the user either runs out of guesses or gets the answer correct. It should give the user messages at appropriate times. It should return TRUEif the user won, FALSEotherwise.
boolPlayGame(intnumber)
e) Write the mainfor this program, which calls PlayGamerepeatedly, providing that function with a random secret number in the allowable range.