Home > Back-end > Turn to the c language, the following procedures do while instead while and for two
Turn to the c language, the following procedures do while instead while and for two
Time:09-26
#include #include #include The main () {//main function int magic, guess, counter;//magic representative computer random number, guess guess the number of users, counter on behalf of the user to guess the number of times the char reply;//character variables reply, on behalf of the user whether to continue the game srand (time (NULL));//generates random number seed do {magic=rand () 100 + % 1;//generates random number counter=0;//the number began to 0 do {printf (" please enter the number=");//user input data the scanf (" % d ", & amp; Guess); counter++; If (guess> Magic) {printf (" Wrong! High ");//high output prompt the user for data} else if (guess CodePudding user response: Good hard to See Ah Find an Version!
CodePudding user response:
#include #include #include The main ()//main function { Int magic, guess, counter;//magic representative computer random number, guess on behalf of the user to guess the number, the number of counter on behalf of the user guess Char reply;//character variables reply, on behalf of the user whether to continue the game Srand (time (NULL));//generates random number seed Do { Magic=rand () % 100 + 1;//generates random number Counter=0;//the number began to 0 Do { Printf (" please enter the number=");//user input data The scanf (" % d ", & amp; Guess); counter++; If (guess> Magic) { Printf (" Wrong! High ");//high output prompt the user for data } Else if (guess{ Printf (" Wrong! Low ");//output prompt the user for low data } The else { Printf (" Right!" );//output right } } while ((guess!=magic) & amp; & (counter<=10));//when the user guess data errors, and guess the number is not more than 10 times, continues to guess Printf (" guess at most 10 times a number, you guess the number of counter=% d \ n ", counter);//the number of output the user guess Printf (" Do you want to continue (y/n)? Enter y representatives continue, n on behalf of the end of the game ");//whether or not to continue to guess the next number The scanf (" % s "1, & amp; The reply); } While (reply=='y');//input y, the game continue to Printf (" the game is over "); }