void menu()
{
printf("********************\n");
printf("***** 1.play *****\n");
printf("***** 0.exit *****\n");
printf("********************\n");
}
void playgame()
{
int m = rand()%100+1;
int g;
int count = 0;
while(1)
{
do{
printf("请猜一个数字:");
scanf("%d",&g);
count++;
if(g>m)
printf("太大了重新输入!\n");
else if(g<m)
printf("太小了重新输入!\n");
else
printf("猜对了!\n");
}
while(g!=m);
printf("您一共猜了%d次,你真是太历害了!\n",count);
}
}
int main()
{
int input = 0;
srand((unsigned int)time(NULL));
do{
menu();
scanf("%d",&input);
switch(input)
{
case 1:
playgame();
break;
case 0:
exit(0);
break;
default:
printf("输入错误!\n");
}
}while(input);
return 0;
}
标签:count,case,游戏,int,while,printf,input,数字 From: https://blog.51cto.com/u_13668714/5980637