新手问道题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.
----------------解决方案--------------------------------------------------------
请你谅解!今天我没有带翻译,铸成不能解答你的问题的大错,实在是太不应该了,我下次一定注意!
----------------解决方案--------------------------------------------------------
编译道猜数字的题,0~1000内的数,属一个输进去,too high too low,就是这样
----------------解决方案--------------------------------------------------------
以下是引用紫石英在2004-10-05 00:00:16的发言:
编译道猜数字的题,0~1000内的数,属一个输进去,too high too low,就是这样
too high too low是跟哪个数比较啊,还是怎么的啊?我英语能力很差,刚才那一大段没看清呢,
----------------解决方案--------------------------------------------------------
程序自动有一个随机数,输进去的书就和它来比较。
先要写InRange来判断输入的数是否在0~1000之内
再写TakeAGuesswhich,来看这个数是不是高或低或正好
还要写PlayGamewhich,来看次数的问题,只能猜10次
最后拼起来,已经假定有random函数了
----------------解决方案--------------------------------------------------------
想起以前电视上一个节目
一件商品有个价格给嘉宾猜 嘉宾报价
主持人告知此价格比商品价格高还是低
才10次 才对了商品归嘉宾
应该是这样吧
----------------解决方案--------------------------------------------------------
int InRange(int x) {if (x<0||x>1000) return 0;else 1;}
char TakeAGuesswhich(int x,int n) {if (x<n) return L;if (x>n) return H; return Y;}
----------------解决方案--------------------------------------------------------
次数判断要不就是很简单的事 要不就不知道怎么写
我也是第一次帮别人
如果不是你要的 请勿骂
[此贴子已经被作者于2004-10-05 02:09:27编辑过]
----------------解决方案--------------------------------------------------------
大家用中文交流好不好。我的英语并不差,但是我觉得还是用中文交流好一点。如果原题是英文,那请各位翻译成中文在贴上来好不好。
----------------解决方案--------------------------------------------------------
我已经翻成中文说了
----------------解决方案--------------------------------------------------------