#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void game()
{
//随机生成一个数字
int ret = 0;
int guess = 0;
ret = rand() % 100+1;
//printf("%d\n", ret);
//猜数字
while (1)
{
printf("猜数字:>");
scanf("%d", &guess);
if (guess < ret)
{
printf("猜小了\n");
}
else
if (guess > ret)
{
printf("猜大了\n");
}
else
{
printf("恭喜您猜对了\n");
break;
}
}
}
int main()
{
int tg = 0;
srand((unsigned)time(NULL));
do
{
printf("******************************\n");
printf("***** 游戏菜单 *****\n");
printf("***** 开始:1 退出:0 *****\n");
printf("******************************\n");
scanf("%d", &tg);
switch (tg)
{
case 1: printf("猜字游戏开始!\n");
game();
break;
case 0: printf("游戏退出\n");
break;
default: printf("您输入错误\n");
break;
}
}
while (1);
system("pause");
return 0;
}
|