标题:新手问道题The Guessing Game
只看楼主
紫石英
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2004-10-4
 问题点数:0 回复次数:10 
新手问道题The Guessing Game
Problem 1: The Guessing Game
You 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.
搜索更多相关主题的帖子: The Game Guessing 
2004-10-04 20:08
knocker的马甲
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2004-10-4
得分:0 
请你谅解!今天我没有带翻译,铸成不能解答你的问题的大错,实在是太不应该了,我下次一定注意!

鄙视live41中............
2004-10-04 23:32
紫石英
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2004-10-4
得分:0 
编译道猜数字的题,0~1000内的数,属一个输进去,too high   too low,就是这样
2004-10-05 00:00
longhao
Rank: 1
等 级:新手上路
帖 子:68
专家分:0
注 册:2004-9-10
得分:0 
以下是引用紫石英在2004-10-05 00:00:16的发言: 编译道猜数字的题,0~1000内的数,属一个输进去,too high too low,就是这样

too high too low是跟哪个数比较啊,还是怎么的啊?我英语能力很差,刚才那一大段没看清呢,


携手共进,陪伴彼此~
2004-10-05 00:15
紫石英
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2004-10-4
得分:0 

程序自动有一个随机数,输进去的书就和它来比较。

先要写InRange来判断输入的数是否在0~1000之内

再写TakeAGuesswhich,来看这个数是不是高或低或正好

还要写PlayGamewhich,来看次数的问题,只能猜10次

最后拼起来,已经假定有random函数了

2004-10-05 00:35
poppylx
Rank: 1
等 级:新手上路
帖 子:367
专家分:0
注 册:2004-9-27
得分:0 

想起以前电视上一个节目

一件商品有个价格给嘉宾猜 嘉宾报价

主持人告知此价格比商品价格高还是低

才10次 才对了商品归嘉宾

应该是这样吧


动于心而静如水
2004-10-05 01:35
poppylx
Rank: 1
等 级:新手上路
帖 子:367
专家分:0
注 册:2004-9-27
得分:0 

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:04
poppylx
Rank: 1
等 级:新手上路
帖 子:367
专家分:0
注 册:2004-9-27
得分:0 

次数判断要不就是很简单的事 要不就不知道怎么写

我也是第一次帮别人

如果不是你要的 请勿骂

[此贴子已经被作者于2004-10-05 02:09:27编辑过]


动于心而静如水
2004-10-05 02:08
Tainform
Rank: 1
等 级:新手上路
帖 子:54
专家分:0
注 册:2004-9-26
得分:0 
大家用中文交流好不好。我的英语并不差,但是我觉得还是用中文交流好一点。如果原题是英文,那请各位翻译成中文在贴上来好不好。
2004-10-05 10:40
紫石英
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2004-10-4
得分:0 
我已经翻成中文说了
2004-10-05 12:59



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-6025-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.724407 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved