Question: I need help so my code will say Not a legal move! if the user selects something other than R, P, or S. and for

I need help so my code will say "Not a legal move!" if the user selects something other than R, P, or S. and for the program to continue running. This is what I have but it doesn't operate properly. C programming.

#include #include

//declare variables int main() { int randSeed; int numGames; int userScore=0; int compScore=0; char userChoice; int tieScore=0; char comp;

//welcome and user input printf("Starting the CPSC 1011 Rock, Paper, Scissors Game! "); printf("Enter a random seed between 0 - 100:"); scanf("%d", &randSeed);

srand(randSeed);

printf(" Enter the number of matches to play: "); scanf("%d", &numGames);

//loop for number of games and letter check for(int i=0; i

//this doesnt work but is what I need to fix else{ printf("Not a legal move! "); } }

//computer selection comp="RPS"[random()%3];

// scoring if(userChoice=='R'){ if(comp=='R'){ printf("\tThe computer chose rock. You tied."); tieScore++; } if(comp=='P'){ printf("\tThe computer chose paper. You lose."); compScore++; } if(comp=='S'){ printf("\tThe computer chose scissors. You win!"); userScore++; } } else if(userChoice=='P'){ if(comp=='R'){ printf("\tThe computer chose rock. You win!"); userScore++; } if(comp=='P'){ printf("\tThe computer chose paper. You tied."); tieScore++; } if(comp=='S'){ printf("\tThe computer chose scissors. You lose."); compScore++; } } if(userChoice=='S'){ if(comp=='R'){ printf("\tThe computer chose rock. You lose."); compScore++; } if(comp=='P'){ printf("\tThe computer chose paper. You win!"); userScore++; } if(comp=='S'){ printf("\tThe computer chose scissors. You tied."); tieScore++; } } // add up of scores after each round printf(" \tScores: "); if(userScore>0){ printf(" You-%d ", userScore); } if(compScore>0){ printf(" Computer-%d ", compScore); } if(tieScore>0){ printf("Ties-%d ", tieScore); } } //final add up of scores and totals printf(" The game of %d matches is complete. The final scores are: ", numGames); printf("You: %d ", userScore); printf("Computer: %d ", compScore); printf("Ties: %d ", tieScore);

return(0); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!