# include
Int main ()
{
Srand ((unsigned) time (0));
Int sun=rand () % 3;
Printf (" 2: you enter 0:1: stone scissors cloth \ n ");
Int lun;
Scanf_s (" % d ", & amp; Lun);
The switch (sun)
{
Case 0:
Printf (" system is stone \ n ");
If (lun==0)
{
Printf (" draw \ n ");
}
If (lun==1); {
Printf (" you lose \ n ");
}
If (lun==2) {
Printf (" you win \ n ");
}
Case 1:
Printf (" system is scissors \ n ");
If (lun==0)
{
Printf (" you win \ n ");
}
If (lun==1); {
Printf (" draw \ n ");
}
If (lun==2) {
Printf (" you lose \ n ");
}
Case 2:
Printf (" system is cloth \ n ");
If (lun==0)
{
Printf (" you lose \ n ");
}
If (lun==1); {
Printf (" you win \ n ");
}
If (lun==2) {
Printf (" draw \ n ");
} default:
Printf (" please enter 012 \ n ");
}
return 0;
}
CodePudding user response:
//rock-paper-scissors
Enum
{
ACTION_MIN,
ACTION_ROCK,
ACTION_SCISSORS,
ACTION_PAPER,
ACTION_MAX,
};
The static char * s_lpActionName [ACTION_MAX]=
{
""," stone ", "scissors", "cloth,"
};
Void RockScissorsPaper (void)
{
Int nRockCount=0;
Int nScissorCount=0;
Int nPaperCount=0;
Int nTotalGame=0;
Int nDrawGame=0;
Int nPlayerWin=0;
Int nComputerWin=0;
Srand (GetTickCount ()/2);
Int nPlayerAction=0;
Int nComputerAction=0;
While (true)
{
If (nTotalGame & lt;
=6){
NComputerAction=rand () % 3 + 1;
}
The else
{
Int nRandom=rand () % nTotalGame;
If (nRandom & lt; NRockCount)
NComputerAction=ACTION_PAPER;
Else if (nRandom & lt; NRockCount + nScissorCount)
NComputerAction=ACTION_ROCK;
The else
NComputerAction=ACTION_SCISSORS;
}
Rock printf (" (1 -, 2 - scissors, 3 - cloth] please enter: ");
If (scanf_s (" % d ", & amp; NPlayerAction)!
=1)break;
If (nPlayerAction & lt;=ACTION_MIN | | ACTION_MAX & lt;=nPlayerAction)
break;
If (nPlayerAction==ACTION_ROCK)
+ + nRockCount;
Else if (nPlayerAction==ACTION_SCISSORS)
+ + nScissorCount;
The else
+ + nPaperCount;
+ + nTotalGame;
Char const * lpResult=NULL;
If (nPlayerAction==nComputerAction)
{
+ + nDrawGame;
LpResult="draw";
}
Else if (nPlayerAction % 3 + 1==nComputerAction)
{
+ + nPlayerWin;
LpResult="players victory";
}
The else
{
+ + nComputerWin;
LpResult="computer victory";
}
VS printf (" % s % s: % s \ r \ n ", s_lpActionName [nPlayerAction], s_lpActionName [nComputerAction], lpResult);
}
Printf (" game over! \r\n");
Printf (" statistics: \ r \ n ");
Printf (" the game number: % d times, winning players: % d times, computer victory: % d times, draw: % d \ r \ n ", nTotalGame, nPlayerWin, nComputerWin, nDrawGame);
Float fRock=0;
Float fScissor=0;
Float fPaper=0;
If (nTotalGame!=0)
{
FRock nRockCount * 100.0=f/nTotalGame;
FScissor nScissorCount * 100.0=f/nTotalGame;
FPaper nPaperCount * 100.0=f/nTotalGame;
}
Printf (" players out of the stone probability: % 2 f % %, players with scissors probability: %, % % 2 f, the probability of players out of the cloth: %, 2 f % % \ r \ n ", fRock, fScissor, fPaper);
Printf (" computer cloth probability: % 2 f % %, computer stone probability: %, % % 2 f, the player with scissors probability: %, 2 f % % \ r \ n ", fRock, fScissor, fPaper);
}
CodePudding user response:
# include
# include
Int main ()
{
Srand ((unsigned) time (0));
Int sun=rand () % 3;
Int lun;
Printf (" 2: you enter 0:1: stone scissors cloth \ n ");
Scanf_s (" % d ", & amp; Lun);
The switch (sun)
{
Case 0:
Printf (" system is stone \ n ");
If (lun==0)
{
Printf (" draw \ n ");
}
//if (lun==1); {//one more here;
If (lun==1) {
Printf (" you lose \ n ");
}
If (lun==2) {
Printf (" you win \ n ");
}
Case 1:
Printf (" system is scissors \ n ");
If (lun==0)
{
Printf (" you win \ n ");
}
//if (lun==1); {//one more here;
If (lun==1) {
Printf (" draw \ n ");
}
If (lun==2) {
Printf (" you lose \ n ");
}
Case 2:
Printf (" system is cloth \ n ");
If (lun==0)
{
Printf (" you lose \ n ");
}
//if (lun==1); {//one more here;
If (lun==1) {//one more here;
Printf (" you win \ n ");
}
If (lun==2) {
Printf (" draw \ n ");
}
Default:
Printf (" please enter 012 \ n ");
}
return 0;
}
For your reference ~
Some suggestion carefully