猜数字游戏
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
void menu()
{
printf("菜单\n");
printf("请选项\n");
printf("输入1(继续游戏)\n");
printf("输入0(退出游戏)\n");
}
void game()
{
int guess = 0;
int a = rand() % 100 + 1;
do
{
printf("请输入数字:");
scanf("%d", &guess);
if (guess > a)
{
printf("数字猜大了\n");
}
else if (guess < a)
{
printf("数字猜小了\n");
}
else
{
printf("恭喜你猜对了\n");
}
} while (guess!=a);
}
int main()
{
srand((unsigned int)time(NULL));
int input = 0;
do
{
menu();
scanf("%d", &input);
switch(input)
{
case 1:
game();
break;
case 0:
printf("退出游戏\n");
break;
default:
printf("选择错误,继续选择");
break;
}
} while (input);
return 0;
}