代码:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void menu()
{
printf("************************\n");
printf("****1.play****0.exit****\n");
printf("************************\n");
}
void game()
{
int ret= rand()%100+1;
int guess;
while (1)
{
printf("猜数字:");
scanf("%d", &guess);
if(ret>guess)
{
printf("猜小了");
}
else if(ret<guess)
{
printf("猜大了");
}
else if(ret==guess)
{
printf("猜对了,泰裤辣\n");
break;
}
}
}
int main()
{
srand((unsigned)time(NULL));
int a;
do
{
menu();
printf("请选择:\n");
scanf("%d",&a);
switch(a)
{
case 0:
printf("结束游戏");
break;
case 1:
game();
break;
default:
printf("选择错误");
}
} while (a);
return 0;
}