#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main()
{
int magic,guess,a=1;
char r;
srand(time(0));
magic = rand() % 100 + 1;
do
{
for(;a<10;)
{
printf("Input a number\n");
scanf("%d",&guess);
a++;
if(guess==magic)
{
printf("Right\n");
a==1? printf("You just guessed once\n"): printf("You have guessed %d times\n",a)break;
}
else
{
printf("Wrong\n");
guess>magic? printf("Too high\n"): printf("Too low\n")
}
}
for(;a==10;)
{
printf("Do you want to play again?\n");
a=1;
scanf("%c",&r);
}
}
while(r=='Y');
}
C语言程序错误...Turbo C&C++ 3 运行有4处错误
答案:2 悬赏:30 手机版
解决时间 2021-05-06 09:21
- 提问者网友:温柔港
- 2021-05-05 23:01
最佳答案
- 五星知识达人网友:持酒劝斜阳
- 2021-05-05 23:15
其实也没什么大错。就以下几点:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()//这里要改int。
{
int magic,guess,a=1;
char r;
srand(time(0));
magic = rand() % 100 + 1;
do
{
for(;a<10;)
{
printf("Input a number\n");
scanf("%d",&guess);
a++;
if(guess==magic)
{
printf("Right\n");
a==1? printf("You just guessed once\n"): printf("You have guessed %d times\n",a);break;//break前面要加;
}
else
{
printf("Wrong\n");
guess>magic? printf("Too high\n"): printf("Too low\n");//这里没加;
}
}
for(;a==10;)
{
printf("Do you want to play again?\n");
a=1;
scanf("%c",&r);
}
}
while(r=='Y');
return 0;
}
全部回答
- 1楼网友:往事隔山水
- 2021-05-06 00:01
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main()
{
int magic,guess,a=1;
char r;
srand(time(0));
magic = rand() % 100 + 1;
do
{
for(;a<10;)
{
printf("Input a number\n");
scanf("%d",&guess);
a++;
if(guess==magic)
{
printf("Right\n");
a==1;
printf("You just guessed once\n");
printf("You have guessed %d times\n",a);
break;
}
else
{
printf("Wrong\n");
guess>magic? printf("Too high\n"): printf("Too low\n") ;
}
}
for(;a==10;)
{
printf("Do you want to play again?\n");
a=1;
scanf("%c",&r);
}
}
while(r=='Y');
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯