Question: What is wrong with my code? Question: Play the rock paper scissors game. Two players enter either rock , paper , or scissors and the
What is wrong with my code?
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:
#include
using namespace std;
string play(string ch1, string ch2);
int main() {
string choice1,choice2; string answer; char ch; cout > choice1; cout > choice2; cout > ch; cout
return 0; }
string play(string choice1, string choice2) { string result; if(choice1.compare("rock") == 0) { if(choice2.compare("scissors") == 0) { result = "Rock breaks scissors Player 1 wins!"; } else if(choice2.compare("paper") == 0) { result = "Paper covers rock Player 2 wins!"; } else { result = "Draw!"; } } if(choice1.compare("paper") == 0) { if(choice2.compare("rock") == 0) { result = "Paper covers rock Player 1 wins!"; } if(choice2.compare("scissors") == 0) { result = "Scissors cut paper Player 2 wins!"; } else { result = "Draw!"; } }
if(choice1.compare("scissors") == 0) { if(choice2.compare("paper") == 0) { result = "Scissors cut paper Player 1 wins!"; } if(choice2.compare("rock") == 0) { result = "Rock breaks scissors Player 2 wins!"; } else { result = "Draw!"; } }
return result; }
Output vs expected output:


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