Home > Back-end >  While, do while in the for loop structure respectively to rewrite the program. The c language a grea
While, do while in the for loop structure respectively to rewrite the program. The c language a grea

Time:09-26


#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
While (1)
{
Srand (time (NULL));//generates random number seed
While (1)
{
Magic=rand () % 100 + 1;//generates random number
Counter=0;//the number began to 0
While (1)
{
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
}
If ((guess!=magic) & amp; & (counter> 10))//when the user guess data errors, and guess the number is not more than 10 times, continues to guess
{
break;
}
}
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);
If (the reply! )
='y'break;
}
Printf (" the game is over ");
}
}