Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructions: Declare your variables: Declare two int variables, playerchoice and computerchoice. The player's choice will be input by the user, and the computer's choice will

Instructions:
Declare your variables: Declare two int variables, playerchoice and computerchoice. The player's choice will be input by the user, and the computer's choice will be pre-set in the program.
Prompt for user input: Use cout to prompt the player to enter a number between 1 and 3(1 for Rock, 2 for Paper, and 3 for Scissors). Use cin to store the player's choice in playerchoice.
Set the computer's choice: Set computerchoice to a constant value between 1 and 3. This will be the computer's move in the game.
Implement your control structures:
Use switch statements to translate playerchoice and computerchoice from numbers to their corresponding strings (Rock, Paper, Scissors), and display them using cout.
Create an if statement that checks for a tie (i.e., playerchoice is equal to computerchoice). If it's a tie, print a message indicating this.
Create an else if statement for each possible win scenario (Rock beats Scissors, Scissors beat Paper, Paper beats Rock). If the player wins, print a message congratulating them.
Create an else statement for the scenarios where the player does not win. If the code reaches this point, it means the player did not tie or win, so they must have lost. In this case, print a message indicating that the player lost.
Test your program: Compile and run your program. Test it with all possible player choices to ensure all scenarios are handled correctly.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

1 what does yellow colour on the map represent?

Answered: 1 week ago