Question: i'm having trouble creating completely random rock, paper, scissors matches between the computer and the player. so that when it asks how many matches you
i'm having trouble creating completely random rock, paper, scissors matches between the computer and the player. so that when it asks how many matches you want to play it generates all of the matches including the score along with who won and lost.
For example:
| Starting the CPSC 1011 Rock, Paper, Scissors Game! Enter the number of matches to play: 3 Match 1: Enter R for rock, P for paper, or S for scissors: R The computer chose scissors. You win! Scores: You-1 Match 2: Enter R for rock, P for paper, or S for scissors: R The computer chose paper. You lose. Scores: You-1 Computer-1 Match 3: Enter R for rock, P for paper, or S for scissors: S The computer chose scissors. You tied. Scores: You-1 Computer-1 Ties-1 The game of 3 matches is complete. The final scores are: You: 1 Computer: 1 Ties: 1 |
Here's my code:
#include
#include
#include
int main(void) {
int R;
int P;
int S;
int matches;
int player;
int playerscore=0;
int computer;
int compscore=0;
char choices;
printf("Staring the CPSC 1011 Rock, Paper, Scissors Game! ");
printf("Enter the number of matches to play: ");
scanf("%d", &matches);
for(int i=0; i printf("Match %d: Enter R for rock, P for paper, or S for scissors: ",(i+1)); scanf("%c", &choices); while(choices==' '){ scanf("%c", &choices); } computer=rand()%3+1; if(choices=='R' || choices=='r'){ if(computer==R){ printf("The computer chose rock. You tied. "); } if(computer==P){ printf("The computer chose paper. You lose. "); compscore++; } if(computer==S){ printf("The computer chose scissors. You win! "); playerscore++; } } else if(choices=='P' || choices=='p'){ if(computer==R){ printf("The computer chose rock. You win!. "); playerscore++; } if(computer==P){ printf("The computer chose paper. You tied. "); } if(computer==S){ printf("The computer chose scissors. You lose. "); compscore++; } } if(choices=='S' || choices=='s'){ if(computer==R){ printf("The computer chose rock. You lose. "); compscore++; } if(computer==P){ printf("The computer chose paper. You win! "); playerscore++; } if(computer==S){ printf("The computer chose scissors. You tied "); } } printf(" "); printf("Computer Score: %d ",playerscore); printf(" You score: %d ",compscore); } return(0); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
