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 "); }

CodePudding user response:

refer to the second floor the wise know already should good karma 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 "); }

Into a while?

CodePudding user response:

Direct replacement is not line?

CodePudding user response:

reference 5 floor wise men know already should good karma response:
direct replacement is not line?

Your knowledge is limited, temporarily not??

CodePudding user response:

reference 5 floor wise men know already should good karma response:
direct replacement is not line?

Your knowledge is limited, temporarily not??

CodePudding user response:

These two loop shrimp knowledge, is first performed again, or judgment to execute, direct replacement is while the replacement do, put the condition changes, such as:
 
Char repl='y'
While (reply=='y') can be replaced the first do
The second direct replacement while ((guess!=magic) & amp; & (counter<=10)) if the shortage can be modified to add 1

CodePudding user response:

Instead FOR the same as above, but FOR writing form, it is to remember to have 2 semicolon, as follows:
 
Char repl='y'
For (; Reply=='y') Replace the first do can
The second direct replacement for (; (guess!=magic) & amp; & (counter<=10);) If the shortage can be modify to add 1
For unlike the while is for can not write any expression, and while you must be an expression, such as: for (;; ), while (1), about the loop statement also is such, no shrimp particularly knowledge can be said,
  • Related