| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1451 人关注过本帖
标题:新手问道题The Guessing Game
取消只看楼主 加入收藏
紫石英
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2004-10-4
收藏
 问题点数:0 回复次数:3 
新手问道题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
紫石英
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2004-10-4
收藏
得分:0 
编译道猜数字的题,0~1000内的数,属一个输进去,too high   too low,就是这样
2004-10-05 00:00
紫石英
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2004-10-4
收藏
得分:0 

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

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

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

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

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

2004-10-05 00:35
紫石英
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2004-10-4
收藏
得分:0 
我已经翻成中文说了
2004-10-05 12:59
快速回复:新手问道题The Guessing Game
数据加载中...
 
   



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

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