#include <stdlib.h>
#include <time.h>
int main()
{
srand((unsigned int)time(NULL));
int a = 0;
int goal=rand()%100+1;
int num=0;
do {
printf("****************\n");
printf("*****1.开始******\n");
printf("*****0.结束******\n");
printf("****************\n");
printf("请选择:");
scanf("%d", &a);
switch (a) {
case 1: {
printf("\n开始游戏");
while (1)
{
printf("请输入数字:");
scanf("%d",&num);
if(num>goal)
{
printf("猜大了\n");
}
else if(num<goal)
{
printf("猜小了\n");
}
else
{
printf("恭喜你,猜中了!\n");
break;
}
}
break;
}
case 0: {
printf("离开游戏\n");
break;
}
default: {
printf("输入错误,请重新输入\n");
break;
}
}
} while (a);
return 0;
猜数字游戏c语言代码实现
最新推荐文章于 2024-11-09 10:41:03 发布