Question

Write a program that plays the popular scissor-rock-paper game. (A scissor can cut a paper, a...

Write a program that plays the popular scissor-rock-paper game. (A scissor can cut a paper, a rock can knock a scissor, and a paper can wrap a rock.) The program randomly generates a number 0, 1, or 2 representing scissor, rock, and paper. The program prompts the user to enter a number 0, 1, or 2 and displays a message indicating whether the user or the computer wins, loses, or draws. Here are sample runs:

Enter your selection: scissor (0), rock (1), paper (2): 1 <enter>

The computer is scissor. You are rock. You won

Enter your selection: scissor (0), rock (1), paper (2): 2 <enter>

The computer is paper. You are paper too. It is a draw

Now revise the program to let the user continuously play until either the user or the computer wins more than two times than its opponent.

!!!!!!!!!!PLEASE ADD IN THE OPTION FOR THE USER TO PLAY CONTINUEOSLY UNTIL SOMEONE WINS MORE THAN TWO TIMES THAN THEIR OPPONENT, THIS IS THE MOST IMPORTANT STEP.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

// main function definition
int main()
{
// To store user selection and computer random selection
int userOption = 0, computerOption = 0;
// To store user score and computer score
int userScore = 0, computerScore = 0;
srand(time(0));

// Loops till either user score is double of computer score or
// computer score is double of user score
do
{
// Generates a random selection for computer
computerOption = (rand() % 2) + 0;
// Displays menu
cout<<"\n\t *********** Rock, Paper, Scissors Game *********** \n";
cout<<"\n \t 0 Scissor \t 1 Rock \t 2 Paper \t 3 Exit \n";

// Loops till valid user choice
do
{
// Accepts user choice
cout<<"\n Enter Your Choice: ";
cin>>userOption;
// Checks if user choice is less than 0 or greater than 3 then invalid
// Display error message and ask again to enter
if (userOption < 0 || userOption > 3)
cout<<"\n Invalid choice. Please enter a valid choice! "<<endl;

// Otherwise valid choice come out of the loop
else
break;
}while(1); // End of do - while loop (While(1) is always true)

// Checks if user choice and computer choice is 1 then display draw
if (userOption == 1 && computerOption == 1)
{
cout<<"\n The computer is Rock. You are Rock too. It is a draw!"<<endl;
// Displays user and computer score.
cout<<"\n User Score: "<<userScore<<"\n Computer Score: "<<computerScore;
}// End of if condition

// Checks if user choice is Rock and computer choice is Paper then computer won
if (userOption == 1 && computerOption == 2)
{
cout<<"\n The computer is Paper. You are Rock. You Lose!"<<endl;
// Displays user and computer score. Increasing computer score by one
cout<<"\n User Score: "<<userScore<<"\n Computer Score: "<<++computerScore;
}// End of if condition

// Checks if user choice is Rock and computer choice is Scissor then user won
if (userOption == 1 && computerOption == 0)
{
cout<<"\n The computer is Scissor. You are Rock. You Won!"<<endl;
// Displays user and computer score. Increasing user score by one
cout<<"\n\n User Score: "<<++userScore<<"\n Computer Score: "<<computerScore;
}// End of if condition

// Checks if user choice is Paper and computer choice is Rock then user won
if (userOption == 2 && computerOption == 1)
{
cout<<"\n The computer is Rock. You are Paper. You Won!"<<endl;
// Displays user and computer score. Increasing user score by one
cout<<"\n\n User Score: "<<++userScore<<"\n Computer Score: "<<computerScore;
}// End of if condition

// Checks if user choice is Paper and computer choice is Paper then tie
if (userOption == 2 && computerOption == 2)
{
cout<<"\n The computer is Paper. You are Paper too. It is a draw!"<<endl;
// Displays user and computer score.
cout<<"\n User Score: "<<userScore<<"\n Computer Score: "<<computerScore;
}// End of if condition

// Checks if user choice is Paper and computer choice is Scissor then computer won
if (userOption == 2 && computerOption == 0)
{
cout<<"\n The computer is Scissor. You are Paper. You Lose!"<<endl;
// Displays user and computer score. Increasing computer score by one
cout<<"\n User Score: "<<userScore<<"\n Computer Score: "<<++computerScore;
}// End of if condition

// Checks if user choice is Scissor and computer choice is Rock then computer won
if (userOption == 0 && computerOption == 1)
{
cout<<"\n The computer is Rock. You are Scissor. You Lose!"<<endl;
// Displays user and computer score. Increasing computer score by one
cout<<"\n User Score: "<<userScore<<"\n Computer Score: "<<++computerScore;
}// End of if condition

// Checks if user choice is Scissor and computer choice is Paper then user won
if (userOption == 0 && computerOption == 2)
{
cout<<"\n The computer is Paper. You are Scissor. You Win!"<<endl;
// Displays user and computer score. Increasing user score by one
cout<<"\n\n User Score: "<<++userScore<<"\n Computer Score: "<<computerScore;
}// End of if condition

// Checks if user choice is Scissor and computer choice is Scissor then tie
if (userOption == 0 && computerOption == 0)
{
cout<<"\n The computer is Scissor. You are Scissor too. It is a draw!"<<endl;
// Displays user and computer score.
cout<<"\n User Score: "<<userScore<<"\n Computer Score: "<<computerScore;
}// End of if condition

// Checks if user and computer score is 0 then continue the game
if(userScore == 0 && computerScore == 0)
continue;

// Checks if computer score is double of user score or
// user score is double of computer score then stop
if((userScore == (2 * computerScore)) || (computerScore == (2 * userScore)))
{
cout<<"\n Game Over!";
break;
}// End of if condition
}while(1); // End of do - while loop (while(1) is always true)
}// End of main function

Sample Output:


*********** Rock, Paper, Scissors Game ***********

0 Scissor 1 Rock 2 Paper 3 Exit

Enter Your Choice: 1

The computer is Rock. You are Rock too. It is a draw!

User Score: 0
Computer Score: 0
*********** Rock, Paper, Scissors Game ***********

0 Scissor 1 Rock 2 Paper 3 Exit

Enter Your Choice: 9

Invalid choice. Please enter a valid choice!

Enter Your Choice: 2

The computer is Rock. You are Paper. You Won!


User Score: 1
Computer Score: 0
*********** Rock, Paper, Scissors Game ***********

0 Scissor 1 Rock 2 Paper 3 Exit

Enter Your Choice: 1

The computer is Rock. You are Rock too. It is a draw!

User Score: 1
Computer Score: 0
*********** Rock, Paper, Scissors Game ***********

0 Scissor 1 Rock 2 Paper 3 Exit

Enter Your Choice: 0

The computer is Scissor. You are Scissor too. It is a draw!

User Score: 1
Computer Score: 0
*********** Rock, Paper, Scissors Game ***********

0 Scissor 1 Rock 2 Paper 3 Exit

Enter Your Choice: 2

The computer is Scissor. You are Paper. You Lose!

User Score: 1
Computer Score: 1
*********** Rock, Paper, Scissors Game ***********

0 Scissor 1 Rock 2 Paper 3 Exit

Enter Your Choice: 1

The computer is Rock. You are Rock too. It is a draw!

User Score: 1
Computer Score: 1
*********** Rock, Paper, Scissors Game ***********

0 Scissor 1 Rock 2 Paper 3 Exit

Enter Your Choice: 1

The computer is Rock. You are Rock too. It is a draw!

User Score: 1
Computer Score: 1
*********** Rock, Paper, Scissors Game ***********

0 Scissor 1 Rock 2 Paper 3 Exit

Enter Your Choice: 2

The computer is Rock. You are Paper. You Won!


User Score: 2
Computer Score: 1
Game Over!

Add a comment
Know the answer?
Add Answer to:
Write a program that plays the popular scissor-rock-paper game. (A scissor can cut a paper, a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a java program that plays the popular scissor-rock-paper game. (A scissor can cut a paper,...

    Write a java program that plays the popular scissor-rock-paper game. (A scissor can cut a paper, a rock can break a scissor, and a paper can cover a rock.) The program randomly generates a number 0, 1, or 2 representing scissor, rock, and paper. The program prompts the user to enter a number 0, 1, or 2 and displays a message indicating whether the user or the computer wins, loses, or draws. Allow the user to continue playing or quit.

  • Assignment C++: Rock-Scissor-Paper & Tic-Tac-Toe i need you to write two different program for RSP and...

    Assignment C++: Rock-Scissor-Paper & Tic-Tac-Toe i need you to write two different program for RSP and TTT: R-S-P Requirement: - write one program that mimics the Rock-Scissor-Paper game. This program will ask user to enter an input (out of R-S-P), and the computer will randomly pick one and print out the result (user wins / computer wins). - User's input along with computer's random pick will be encoded in the following format: -- user's rock: 10 -- user's scissor: 20...

  • Objective: Write a program that simulates a game of rock, paper, scissors between a human and...

    Objective: Write a program that simulates a game of rock, paper, scissors between a human and the computer in best 2 out of 3 rounds. Requirements: . The player can enter either "rock", "paper", or "scissors'". o If the player enters anything other than that the computer automatically gets a point . The computer randomly selects one of the gestures o Use the Random type to make this easier o Also make sure you import java.util.Random o You can use...

  • C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this...

    C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this game against the computer. The program should work as follows: When the program begins, a random number between 1 and 3 is generated. If the number is 1, the computer has chosen rock. If the number is 2, the computer has chosen paper. If the number is 3, the computer has chosen scissors. Don't display the computer's choice yet. Use a menu to display...

  • Write a program to score the paper-rock-scissor game. Each of two users types in either P,R...

    Write a program to score the paper-rock-scissor game. Each of two users types in either P,R or S. The program call function Find winner to announces the winner. For determining the winner: Paper covers rock, Rock breaks scissors, Scissors cut paper, or it is a tie. Be sure to allow the users to use lower case as well as uppercase letters. Your program should include a loop that lets the user play again until the user says she or he...

  • java pls Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of...

    java pls Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of the common game Rock Paper Scissors that is often used to pass time (or sometimes to make decisions.) The rules of the game are outlined below: • • Scissors cuts Paper Paper covers Rock Rock crushes Lizard Lizard poisons Spock Spock smashes Scissors Scissors decapitates Lizard Lizard eats Paper Paper disproves Spock Spock vaporizes Rock Rock crushes Scissors Write a program that simulates the...

  • In python language Write a program that lets the user play the game of Rock, Paper,...

    In python language Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: 1. When the program begins, a random number in the range of 1 and 3 is generated. 1 = Computer has chosen Rock 2 = Computer has chosen Paper 3 = Computer has chosen Scissors (Dont display the computer's choice yet) 2. The user enters his or her choice of “Rock”, “Paper", “Scissors" at...

  • In this problem, you’ll play a simple rock, paper, scissors game. First, you’ll ask the user...

    In this problem, you’ll play a simple rock, paper, scissors game. First, you’ll ask the user to pick rock, paper, or scissors. Then, you’ll have the computer randomly choose one of the options. After that, print out the winner! You should keep playing the game until the user hits enter. Note: You’ll need to implement a method called String getWinner(String user, String computer). Luckily, you just wrote that in an earlier program! Here is a sample run of the program....

  • IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors...

    IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet....

  • (Java) Write a program that lets the user play the game of Rock, Paper, Scissors against...

    (Java) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet. The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT