#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void menu()//菜单
{
printf(" \n");
printf(" 1.进入游戏。 \n");
printf(" 0.退出游戏。 \n");
printf(" \n");
}
void game()//游戏
{
int n = rand ()%100+1;
int guess = 0;
while (1)
{
printf("请猜数字:");
scanf("%d", &guess);
if (guess>n)
{
printf("猜大了!");
}
else if(guess<n)
{
printf("猜小了!");
}
else
{
printf("猜对了!!!");
break;
}
}
}
int main()
{
int x = 0;
srand((unsigned int)time(NULL));
do
{
menu();
printf("请选择:\n");
scanf("%d", &x);
switch (x)
{
case 1:
game();
break;
case 0:
printf("退出游戏\n");
break;
default:
printf("选择错误,重新选择:\n");
break;
}
} while (x);
return 0;
}
09-11
926
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-16
2万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-29
851
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交