c语言 猜数游戏
呃,刚学c语言不久,求大神帮忙看看这段程序哪儿出问题了,我编译完了toolow和toohigh怎么跟随机出现的似的。。题目要求:1.Guessthenumber.Thep...
呃,刚学c语言不久,求大神帮忙看看这段程序哪儿出问题了,我编译完了too low和too high怎么跟随机出现的似的。。
题目要求:
1. Guess the number. The program randomly generates an integer between 1 and 1000. We will guess this number. Before the guess, the program mentions the following information:
I have a number between 1 and 1000.
Can you guess my number?
Please type your guess.
After the user inputs the number:
<1>If the input number is smaller than the generated number, output:Too low. Try again.
<2>If larger,output:Too high.Try again. Then mention:Please type your next guess.
Repeat it until the input number is same with the generated number.
<3> The input number is same with the generated number,output:Excellent!You guessed the number!
这是我的程序:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int a,m;
printf("I have a number between 1 and 1000.\nCan you guess my number?\nPlease type your guess.\n");
scanf("%d",&a);
srand(time(NULL));
m=1+(int)(rand()%1000);
while(a!=m)
{
if(m>a)
printf("Too high, try again");
else
printf("Too low, try agian");
printf("\nPlease type your next guess:\n");
scanf("%d",&a);
}
printf("\nExcellent!You guessed the number!");
system("pause");
return 0;
} 展开
题目要求:
1. Guess the number. The program randomly generates an integer between 1 and 1000. We will guess this number. Before the guess, the program mentions the following information:
I have a number between 1 and 1000.
Can you guess my number?
Please type your guess.
After the user inputs the number:
<1>If the input number is smaller than the generated number, output:Too low. Try again.
<2>If larger,output:Too high.Try again. Then mention:Please type your next guess.
Repeat it until the input number is same with the generated number.
<3> The input number is same with the generated number,output:Excellent!You guessed the number!
这是我的程序:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int a,m;
printf("I have a number between 1 and 1000.\nCan you guess my number?\nPlease type your guess.\n");
scanf("%d",&a);
srand(time(NULL));
m=1+(int)(rand()%1000);
while(a!=m)
{
if(m>a)
printf("Too high, try again");
else
printf("Too low, try agian");
printf("\nPlease type your next guess:\n");
scanf("%d",&a);
}
printf("\nExcellent!You guessed the number!");
system("pause");
return 0;
} 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询