#include<time.h>
#include<stdio.h>
void menu()
{
printf("***********************\n");
printf("*** 1.play 0.exit ***\n");
printf("***********************\n");
}
void game()
{
// 生成随机数
// rand(); 生成随机数
// printf("猜数字\n");
int ret = 0;
int guess = 0; //接收猜数字的 guess
ret = rand()%100+1;
// printf("%d\n",ret);
while(1)
{
printf("请猜数字:>\n");
scanf("%d", &guess);
if(guess > ret)
{
printf("猜大了");
}
else if(guess < ret)
{
printf("猜小了");
}
else
{
printf("恭喜你,猜对啦!\n");
break;
}
}
}
int main()
{
int input =0;
srand((unsigned int)time(NULL));
do
{
menu();
printf("请选择:>");
scanf("%d", &input);
switch (input)
{
case 1:
game(); //猜数字游戏
break;
case 0:
printf("退出游戏\n");
break;
default:
printf("选择错误\n");
break;
}
} while (input);
return 0;
}
C 语言基础 -猜大小
最新推荐文章于 2024-02-26 12:18:03 发布