//系统随机生成0--100的数,你猜是多少,大了或小了提示,猜对为止。
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int a=0,b=-1;
int num = 1;
while (num == 1)
{
printf("是否进行游戏(1:是 0:否)");
f:
scanf("%d", &num);
if ((num!= 0 )&&( num!= 1))
{
printf("输入有误 请重新输入!");
goto f;
}
if (num == 1)
{
printf("游戏开始!\n");
srand(time(NULL));
a = rand()%100;
while (1)
{
printf("请输入你猜得数:");
scanf("%d",&b);
if (a > b)
printf("小了!");
else if (a<b)
printf("大了!");
else
{
printf("恭喜你猜对了!是%d\n", a);
break;
}
}
}
if (num == 0)
return 0;
}
return 0;
}
转载于:https://blog.51cto.com/shaungqiran/1677167