永发信息网

帮忙看看我这个C语言程序是什么问题

答案:1  悬赏:70  手机版
解决时间 2021-06-06 04:29
  • 提问者网友:不爱我么
  • 2021-06-05 12:58
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

main()
{
char A;
int m, g;

do
{
srand(time(NULL));
m=(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");
scanf("%d", &g);

while(g!=m)
{
if(g<m)
printf("Too low.Try again.\n");
else
printf("Too high.Try again.\n");
scanf("%d", &g);
}
printf("Excellent!You guessed the number!\n");
printf("Would you like to play again(y or n)?\n");
scanf("%c", &A);
}
while(A=='y');


system("pause");
return 0;

}


其中scanf("%c", &A);一句总是不执行,循环一次程序就结束了

请高手看看是怎么回事,谢谢

最佳答案
  • 五星知识达人网友:轮獄道
  • 2021-06-05 14:10
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

main()
{
char A;
int m, g;

do
{
srand(time(NULL));
m=(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");
scanf("%d", &g);

while(g!=m)
{
if(g<m)
printf("Too low.Try again.\n");
else
printf("Too high.Try again.\n");
scanf("%d", &g);
}
printf("Excellent!You guessed the number!\n");
printf("Would you like to play again(y or n)?\n");
while( getchar() != '\n' );
scanf("%c", &A);
}
while(A=='y');


system("pause");
return 0;

}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯