21. Comprehensive application of rock paper scissors

/*
Loop: that is, repetition. When certain statements are to be executed multiple times,
these statements will be placed in the curly brackets of the loop.

Loop body: is the collection of all statements within the loop curly braces.

The number of loops is often defined by an integer variable to control, called a loop variable.

Three necessary expressions of loop variables:
1. Initial value, which is an assignment statement, such as: x=1
2. Final limit, is a relationship or a relationship plus a logical expression, such as: x<=100
3. Step size, is a Compound assignment statement (will change the value of the loop variable), such as: x++, or

how the three expressions of the x+=2 loop variable should be combined:
1. If the initial value is less than the final limit, then the relational expression should be less than or
less than or equal to , the step size is += or ++
2. The initial value is greater than the terminal limit, then, the relational expression should be greater than or
greater than or equal to, and the step size is -= or --

When the loop terminal limit is false, the loop ends, and the loop variable The value is "greater than the limit" or "less than the limit"

The three expressions of the for loop variable and the execution order of the loop body:
1. Initial value
2. Final limit (execute the loop body when it is true, and end the loop when it is false (that is, after the closing curly bracket of the loop))
3. Loop body
4 .step size (will return to the end limit later, to judge true and false)
*/
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
void main()
{
int jiqi,ren;
int n;

srand((unsigned)time(NULL));//Ensure that the random numbers generated by rand() are different each time
jiqi=rand()%3+1;

n=0;
printf("Please punch ( 1. Rock; 2. Scissors; 3. Cloth):");
re:n=scanf("%d",&ren);
if(n!=1||ren<1||ren>3)
{
printf( "The punch is wrong, please retype:");
fflush(stdin);
goto re;
}

switch(ren)
{
case 1:
printf("You throw a stone\n");
switch(jiqi)
{
case 1:printf("The computer came out with rocks, a draw\n");break;
case 2:printf("The computer came out with scissors, you won\n");break;
case 3:printf("The computer came out If it's cloth, you lose\n");break;
}
break;
case 2:
printf("What you get is scissors\n");
switch(jiqi)
{
case 1:printf("What the computer outputs is rock, You lose\n");break;
case 2:printf("The computer came out with scissors, a draw\n");break;
case 3:printf("The computer gave out cloth, you won\n"); break;
}
break;
case 3:
printf("You got a cloth\n");
switch(jiqi)
{
case 1: printf("The computer got a stone, you won\n");break;
case 2 :printf("The computer came out with scissors, you lost\n");break;
case 3:printf("The computer came out with cloth, a draw\n");break;
}
break;
}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325794123&siteId=291194637