Question: Help with this Code. C++ Question: Play the rock paper scissors game. Two players enter either rock , paper , or scissors and the winner
Help with this Code. C++
Question:
Play the rock paper scissors game. Two players enter either rock, paper, or scissors and the winner is determined as follows:
paper covers rock rock breaks scissors scissors cut paper.
Ask the user if s/he wants to play again. BE SURE to include a function called play as shown in the template.
Sample run:
Play rock, paper, scissors Player 1: rock Player 2: paper Player 2 wins -- Paper covers rock Do you want to continue? (yes or no): yes Player 1: scissors Player 2: rock Player 2 wins -- Rock breaks scissors Do you want to continue? (yes or no): no
My Code:
Please only change the highlighted section:
#include
int play(string choice1, string choice2) { int result;
int fact=1; if(fact==1) { if(choice1.compare("rock")== 0) { if(choice2.compare("scissors")== 0) { result =1; fact=0; } else if(choice2.compare("paper")==0) { result = 2; fact=0; } } if(choice1.compare("paper") == 0) { if(choice2.compare("rock") == 0) { result = 1; fact=0; } if(choice2.compare("scissors") == 0) { result = 2; fact=0; } } if(choice1.compare("scissors") == 0) { if(choice2.compare("paper") == 0) { result = 1; fact=0; } if(choice2.compare("rock") == 0) { result =2; fact=0; }
} if(choice2.compare("rock")== 0) { if(choice1.compare("scissors")== 0) { result =2; fact=0; } else if(choice1.compare("paper")==0) { result = 1; fact=0; } } if(choice2.compare("paper") == 0) { if(choice1.compare("rock") == 0) { result = 2; fact=0; } if(choice1.compare("scissors") == 0) { result =1; fact=0; }
} if(choice2.compare("scissors") == 0) { if(choice1.compare("paper") == 0) { result = 2; fact=0; } if(choice1.compare("rock") == 0) { result = 1; fact=0; } } } if(fact==0) { return result; } else { return 0; } }
int main() { string p1, p2; cout > p1; cout > p2; cout > goOn; cout
Output vs Expected:

1. Compare output rock paper e3 Input scissors rock no Play rock, paper, scissors Player 1: rock Player 2: paper Player 2 wins! Do you want to continue? (yes or no) yes Player 1: scissors Player 2: rock Player 2 wins! Do you want to continue? (yes or no) no Your output D you want tcontinue ? (yes r no): yes Play rock, paper, scissors Player 1: rock Player 2: paper apeI Covers roc Player 2 wins! Do you want to continue? (yes or no) yes Player 1: scissors Plaver 2: rock Paper covers rockJ Expected output ayer : roc Rock breaks scissors Player 2 wins! Do you want to continue? (yes or no) no
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
