#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void menu()
{
printf("*********** 1.猜数字 ********\n");
printf("*********** 0.退出游戏 ********\n");
}
void game()
{
int input = 0;
int key = 0;
key = rand() % 100 + 1;
printf("请输入所猜的数字:");
while (1)
{
scanf("%d", &input);
if (input > key)
{
printf("猜大了,请重新选择:\n");
}
else if (input < key)
{
printf("猜小了,请重新选择:\n");
}
else
{
printf("恭喜你,找到了,key=%d", key);
break;
}
}
}
int main()
{
menu();
int input = 0;
srand((unsigned)time(NULL));
printf("请选择\n");
do
{
scanf("%d", &input);
switch (input)
{
case 1:
game();
input=0;
break;
case 0:
break;
default:
printf("选择错误,请重新选择:");
}
} while (input);
system("pause");
return 0;
}
猜数字
最新推荐文章于 2019-07-06 17:23:48 发布