#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int ret,guess;
void manu()
{
printf("~~~welcome to the game\n");
printf("~~~press 1 start game\n~~~press 0 exit game\n");
}
void game()
{
ret=rand()%100+1;
printf("随机数是:\n");
while(1)
{
printf("please guess the number:");
scanf("%d",&guess);
if(guess>ret)
{
printf("guess is more than rand unmber\n");
}
else if(guess<ret)
{
printf("guess is less than rand number\n");
}
else
{
printf("congratulate guess right\n");
break;
}
}
}
int main () {
int input;
srand((unsigned int)time(NULL));
do
{
manu();
printf("请选择:\n");
scanf("%d",&input);
switch(input)
{
case 1:
game();
break;
case 0:
printf("退出游戏\n");
break;
default:
printf("选择错误\n");
break;
}
}
while(input);
return 0;
}