#include<string.h>
#include <stdio.h>
#include<windows.h>
#include<stdlib.h>
#include<time.h>
void menu()
{
printf("欢迎来到猜数字游戏\n");
}
void game()
{
int guess;
int num;
num=rand()%100+1;
while(1)
{
printf("请输入数字\n");
scanf("%d",&guess);
if(guess>num)
{
printf("大了\n");
}
else if(guess<num)
{
printf("小了\n");
}
else
{
printf("恭喜你,答对了\n");
break;}
}
}
int main()
{
int input;
srand((unsigned int)time(NULL));
do
{
menu();
printf("开始请按1,退出请按0>:\n");
scanf("%d",&input);
switch(input)
{
case 1:
game();
break;
case 0:
break;
default:
printf("输入错误\n");
break;
}
}while(input);
return 0;
}
标签:guess,数字,int,break,小游戏,printf,input,include From: https://blog.51cto.com/u_16285400/8072521