#include<stdio.h>
#include<stdlib.h>
#include<time.h>
main()
{
int a,guess,ret,cishu;
char reply;
srand(time(NULL));
do{
cishu=0;
a=rand()%10+1;
do{
printf("请猜一个数:");
ret=scanf("%d",&guess);
while(ret!=1){
fflush(stdin);
printf("输入的必须是数字,请重新输入:");
ret=scanf("%d",&guess);
}
cishu++;
if(guess<a){
printf("too samll!\n\n");
}else if(guess>a){
printf("too big!\n\n");
}else{
printf("right!\n");
}
}while(guess!=a&&cishu<10);
printf("尝试次数:%d\n\n",cishu);
printf("你还想继续吗?:");
scanf(" %c",&reply);
fflush(stdin);
if(reply=='n'||reply=='N'){
break;
}
}while(reply!='y'||reply!='Y');
}
使用do while ,while的猜数游戏
最新推荐文章于 2023-02-25 17:14:25 发布