#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void menu()
{
printf("********************\n");
printf("* 1.play 0.exit *\n");
printf("********************\n");
}
void game()
{
//1.生成一个随机数
//拿时间戳来获取猜数字的初始值
//time_t
int ret = rand() % 100 + 1;
//2.猜数字
while (1)
{
int guess;
printf("请猜数字:\n");
scanf("%d", &guess);
if (ret > guess)
{
printf("猜小了\n");
}
else if (ret < guess)
{
printf("猜大了\n");
}
else
{
printf("恭喜你 猜对了!\n");
break;
}
}
}
int main()
{
srand((unsigned int)time(NULL));
int input = 0;
do{
menu();
printf("请选择\n");
scanf("%d", &input);
switch (input)
{
case 1:
game();
break;
case 0:
printf("退出游戏\n");
break;
default:
printf("选择错误\n");
break;
}
} while (input);
}
10-16
2万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-09
4961
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-04
1336
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-24
2万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)