#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<string.h>
void menu()
{
printf(" 猜数字\n");
printf(" 1.开始游戏\n");
printf(" 0.退出游戏\n");
}
void game()
{
int ret = 0;
rand();
int guess = 0;
ret = rand() % 100 + 1;
while (1)
{
printf("请输入数字:>\n");
scanf_s("%d", &guess);
if (guess > ret)
printf("猜大了\n");
else if (guess < ret)
printf("猜小了\n");
else
{
printf("恭喜你,猜对了!\n");
break;
}
}
}
int main()
{
menu();
int a = 0;
srand((unsigned int)time(NULL));
do
{
printf("请输入:>\n");
scanf_s("%d", &a);
switch (a)
{
case 1:
game();
case 0:
printf("退出游戏\n");
break;
default:
printf("输入错误,请重新输入:>");
break;
}
} while (a);
return 0;
}
标签:guess,数字,int,ret,break,小游戏,printf,include From: https://blog.51cto.com/u_15829881/5786213