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

C++ HELP!!! DO NOT SUBMIT ANSWER WITHOUT FIRST CHECKING IF IT COMPILES ( g++ -st

ID: 3790588 • Letter: C

Question

C++ HELP!!! DO NOT SUBMIT ANSWER WITHOUT FIRST CHECKING IF IT COMPILES (g++ -std=c++11 blah.cpp -o blah), PLS!!! I HAVE USED 3 QUESTIONS ON THIS AND IT IS SO FRUSTRATING.

The switch statement

Here is the question in its entirety, but the actual problem is at the end. I just felt that I would give an overview of what I am asking. The program has to be in c++ (.cpp) and must compile as such. I use linux.

Create the first part of a Rock, Paper, Scissors game. Tell the user what you are playing and then ask them to choose either rock, paper or scissors. After they choose tell them what they chose. If they make an invalid choice, let them know. You must use a swich statement for this lab.

Your text must exatly match the examples below:

Example 1 with correct input:

Let's play Rock, Paper, Scissors

Enter 1 for rock, 2 for paper, 3 for scissors

2

You chose paper

Example 2 with incorrect input:

Let's play Rock, Paper, Scissors

Enter 1 for rock, 2 for paper, 3 for scissors

5

5 is not a valid choice

Explanation / Answer

# include <ctime>
# include <cstdlib>
#include <iostream>
using namespace std;

int main()
{
int playerChoice = 0;

cout << "Let's play Rock, Paper, Scissors";
cout <<" Enter 1 for rock, 2 for paper, 3 for scissors" << endl;
cin >> playerChoice;

switch(playerChoice)
{
case 1:
if (playerChoice == 1)
{
cout << " You chose rock ";
break;
}

case 2:

if (playerChoice == 2)
{
cout << " You chose paper ";
break;
}

case 3:

if (playerChoice == 3)
{
cout << " You chose scissors ";
break;
}
default:
cout << playerChoice << " is not a valid choice." << endl;
}
return 0;
}