Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The game of rock paper scissors is a two player game in which each each player p

ID: 3601570 • Letter: T

Question

The game of rock paper scissors is a two player game in which each each player picks one of the three
selections: rock, paper and scissors. The game is decided using the following logic:ROCK defeats SCISSORS (“smashes”)
PAPER defeats ROCK (“wraps”)
SCISSORS defeats PAPER (“slices”)
If both players choose the same selection the game ends in a tie. Write a c++ program that asks the user to
select one of the three choices. The computer will randomly choose one of the three options as well.
Your program will then display both players' selections as well as the who won the game.
Be sure to divide your program into functions which perform each major task.

Explanation / Answer

#include <iostream>
#include <stdlib.h>

using namespace std;

void printMenu(){
cout << "Choose from rock paper scissors" << endl;
cout << "1. Rock" << endl;
cout << "2. Paper" << endl;
cout << "3. Scissors" << endl;
}

int getComputerChocie() {
return rand() % 3 + 1;
}

string getDisplayFromint(int choice) {
switch(choice) {
case 1:
return "Rock";
case 2:
return "Paper";
case 3:
return "Scissors";
}
}

void printResult(int choice, int compChoice) {
cout << "You choose: " << getDisplayFromint(choice);
cout << "Computer choose: " << getDisplayFromint(compChoice);
if (choice == compChoice) {
cout << "Tie";
}
else if(choice == 1 && compChoice == 3) {
cout << "ROCK smashes SCISSORS" << endl;
cout << "You won!" << endl;
}
else if(choice == 3 && compChoice == 1) {
cout << "ROCK smashes SCISSORS" << endl;
cout << "You loose!" << endl;
}
else if(choice == 2 && compChoice == 1) {
cout << "Paper wraps SCISSORS" << endl;
cout << "You won!" << endl;
}
else if(choice == 1 && compChoice == 2) {
cout << "Paper wraps SCISSORS" << endl;
cout << "You loose!" << endl;
}
else if(choice == 3 && compChoice == 2) {
cout << "SCISSORS slices Paper" << endl;
cout << "You won!" << endl;
}
else if(choice == 2 && compChoice == 3) {
cout << "SCISSORS slices Paper" << endl;
cout << "You loose!" << endl;
}
}

int main()
{
printMenu();
int choice;
cin >> choice;
  
int compChoice = getComputerChocie();  
printResult(choice, compChoice);
return 0;
}

Sample run

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote