c语言--(10次机会,提示是否继须)

#include

#include

#include

int main()

{

int magic;

int ret;

int guess;

int counter = 0;

char reply;

srand(time(NULL));

do{

counter = 0;

magic = rand() % 100 + 1;

do{

printf("please guess a magic numbre:");

ret = scanf("%d",&guess);

while(ret ! = 1)

{

while(getchar() ! = '\n');

printf("please guess a magic number:");

ret = scanf("%d",&guess);

}

counter++;

if(guess>magic)

printf("Wrong! Too big!\n");

else if(guess

printf("Wrong! Too small!\n");

else

printf("Right!\n");

}while(guess ! = magic && counter < 10);

printf("counter = %d\n",counter);

printf("Do you want to continue(Y/N or y/n)?");

scanf("%c",&reply);

}while(reply == 'Y'||reply == 'y' );//输入Y或者y则程序继续

return 0;

}

你可能感兴趣的:(c语言)