#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void menu()//菜单
{
printf("*********************************\n");
printf("**** 1.play 0.exit ****\n");
printf("*********************************\n");
}
void game()//游戏内容
{
int ret = rand()%100+1;//生成一个随机数,用ret来接收(1-100之间的数)
int guess = 0;
printf("猜猜数字:>");
while (1)
{
scanf("%d", &guess);
if (guess > ret)
printf("猜大了,再猜\n");
else if (guess < ret)
printf("猜小了,再猜\n");
else if (guess == ret)
printf("恭喜你,猜对了!\n");
}
}
int main()
{
srand((unsigned int)time(NULL));//时间戳,用来设置随机数的生成起点
int num = 0;
do
{
menu();
printf("请选择:>");
scanf("%d", &num);
switch (num)
{
case 1:
game();
break;
case 0:
printf("退出游戏\n");
break;
default:
printf("请重新输入\n");
break;
}
} while (num);
return 0;
}