(5) repeatedly accept player input, only until the number is guessed
The C program uses the else if statement block to implement a set of conditional statement blocks with multiple different conditional statements. Its usage is shown as follows:
If (condition 1 ){
.........
}
Else if (condition 2 ){
..........
}
Else if (Condition 3 ){
.........
}
......
......
Else if (condition n ){
.........
}
Else {
.........
}
All contents of the good AI Park blog is original, if reproduced please indicate the source http://blog.csdn.net/myhaspl/
This statement block structure is used to implement this step.
# Include
# Include
# Include
Int getnumber (){
Srand (int) time (0 ));
Return rand () % 499 + 1;
}
Int main (){
Int mynum;
Int ispass = 0;
Int guessnum = getnumber ();
While (1 ){
While (1 ){
Printf ("hello, please enter a number :");
Scanf ("% d", & mynum );
If (mynum> 500 | mynum <1 ){
Printf ("numbers are limited to \ n between 1-500 ");
}
Else {
Printf ("\ n the number you entered is: % d \ n", mynum );
Break;
}
}
If (mynum> guessnum ){
Printf ("the number is big! \ N ");
}
Else if (mynum
Printf ("the number is small! \ N ");
}
Else {
Printf ("Congratulations, you guessed it! \ N ");
Break;
}
}
}
Dp @ dp :~ /Cquick % gcc guessnum. c-o myguess
Dp @ dp :~ /Cquick %./myguess
Hello, please enter a number: 55
The number you entered is: 55
The number is small!
Hello, please enter a number: 280
The number you entered is: 280
The number is small!
Hello, please enter a number: 350
The number you entered is: 350
The number is small!
Hello, please enter a number: 400
The number you entered is: 400
The number is small!
Hello, please enter a number: 488
The number you entered is: 488
The number is big!
Hello, please enter a number: 420
The number you entered is: 420
The number is small!
Hello, please enter a number: 450
The number you entered is: 450
The number is big!
Hello, please enter a number: 440
The number you entered is: 440
The number is big!
Hello, please enter a number: 430
The number you entered is: 430
Congratulations! You guessed it!