作业帮 > 综合 > 作业

编写C程序来玩“猜数字”的游戏,如下所示:通过在1-1000这个范围内随机选择整数的方式,来选择一个待猜的数字.然后程序

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/14 03:38:42
编写C程序来玩“猜数字”的游戏,如下所示:通过在1-1000这个范围内随机选择整数的方式,来选择一个待猜的数字.然后程序显示:
I have a number between 1 and 1000.
Can you guess my number?
Please type your first guess.
然后,玩家输入第一个待猜的数字.程序使用如下信息中的一条进行响应:
1.Excellent You guessed the number!
Would you like to play again (y or n)?
2.Too low.Try again.
3.Too high.Try again.
修改以上的程序以计算玩家猜测的次数.如果这个数字等于10或者更小,
就显示Either you know the secret or you got lucky!(您要么知道了秘密,要么就是非常走运!)
如果玩家在10次猜测中猜中了这个数字,显示Aha!you know the secret!
如果玩家的猜测超过了10次,就显示you should be able to be better!为什么不在10次之内猜中他呢?
给,已经编译运行确认:
#include
#include
#include
void main()
{
int trueNum,guessNum;
int count=0;
char choose;
srand((unsigned)time(NULL));
do
{
trueNum=rand()%1000+1;
printf("I have a number between 1 and 1000.\n");
printf("Can you guess my number?\n");
printf("Please type your first guess.\n");

while(1)
{
scanf("%d",&guessNum);

if(guessNum==trueNum)
{
printf("Excellent ! You guessed the number!\n");

if(count