使用do while ,while的猜数游戏

#include
#include
#include
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(guessprintf("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');
}

你可能感兴趣的:(记录)