Question

(Game: scissor, rock, paper) Write a program that plays the popular scissor-rockpaper game. (A scissor can...

(Game: scissor, rock, paper) Write a program that plays the popular scissor-rockpaper 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.

Homework Answers

Answer #1

Note:I implemented this program using C++

CODE:

OUTPUT:

Raw_code:

//including iostream for input and output streams
#include<iostream>
//including ctime because we use the time function for random generation
#include<ctime>
//including cstdlib for exit function
#include<cstdlib>
//using standard namespace
using namespace std;
//beginning of the main funcion
int main()
{
   //srand function sets the starting point for producing of random integers
   srand((unsigned)time(0));
   //game array of 3 values 0,1 and 2 which represents scissor, rock and paper respectively
   int game[4]={0,1,2};//[scissor, rock, and paper]
   //integer variable to take value from the user either 0 or 1 or 2
   int n;
   //int variable selecting option purpose
   int op;
   //if the op is 0 this loop is terminated
   while(op!=0)
   {
       //menu based program
       cout<<"\n0.exit\n1.Play"<<endl;
       //taking the option from the user
       cout<<"\nEnter the option:";
       cin>>op;
       switch(op)
       {
           //if the user select 0 option then we exit from the game
           case 0:exit(0);
                   break;
           case 1:cout<<"Enter 0,1 or 2[scissor, rock, and paper]:";
                   cin>>n;
                   int i;
                   //random generation of 0,1 and 2
                   //which represents scissor, rock and paper respectively
                   i=game[rand()%3];
                   //our value
                   cout<<"ours:"<<n<<endl;
                   //randomly generated value
                   cout<<"opponent:"<<i<<endl;
                   //if the value that we given is equal to randomly generated
                   //value it shows draws
                   if(n==i)
                       cout<<"draws"<<endl;
                   //if we select scissor and opponent select paper we wins
                   else if(n==0&&i==2)
                       cout<<"Wins"<<endl;
                   //if we select rock and opponent select scissor we wins
                   else if(n==1&&i==0)
                       cout<<"Wins"<<endl;
                   //if we select paper and opponent select rock we wins
                   else if(n==2&&i==1)
                       cout<<"Wins"<<endl;
                   //in all other cases we loses
                   else
                       cout<<"Loses"<<endl;
                       break;
           default:cout<<"Invalid option";
                   break;  
       }
   }

   return 0;
}

Note:THIS IS ONE OF THE BASIC WAY TO IMPLEMENT THIS PROGRAM USING C++

in the above there is no specification of language

************For any queries comment me in the comment box*******************

Know the answer?
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
Similar Questions
R-S-P Requirement: - write one C++ program that mimics the Rock-Scissor-Paper game. This program will ask...
R-S-P Requirement: - write one C++ 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 -- user's paper:            30 -- comp's rock:            1 -- comp's scissor:        2 -- comp's...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the...
Using Java, write a program that allows the user to play the Rock-Paper-Scissors game against the computer through a user interface. The user will choose to throw Rock, Paper or Scissors and the computer will randomly select between the two. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should then reveal the computer's choice and print a statement indicating if the user won, the computer won, or if it was a tie. Allow...
Write a program that plays a number guessing game with a human user. The human user...
Write a program that plays a number guessing game with a human user. The human user will think of a number between 1 and 100, inclusive. Then the program has to guess what the user entered. keep track of the number of interaction it takes for the computer to guess the number. sample run: enter number to be guessed:88 output: you entered 88, and it took the program 3 iterations to guess.
Write a Python program that plays a number guessing game with a human user. The human...
Write a Python program that plays a number guessing game with a human user. The human user will think of a number between 1 and 100, inclusive. Then the program has to guess what the user entered. keep track of the number of interaction it takes for the computer to guess the number. sample run: enter number to be guessed:88 output: you entered 88, and it took the program 3 iterations to guess.
Code the Rock Paper Scissors program: a. Get a move choice from player A which must...
Code the Rock Paper Scissors program: a. Get a move choice from player A which must be R, P, S or r, p, s Exit with System.exit(0) and an error msg if the user fails to respond correctly b. Get a move choice from player B in the same manner Again, Exit with System.exit(0) and an error msg if the user fails to respond correctly c. Display the results using the accepted phrases from the game Rock breaks Scissors, Paper...
Nicolás is a great bettor in the famous game of "rock, paper or scissors" and whenever...
Nicolás is a great bettor in the famous game of "rock, paper or scissors" and whenever he can, he tries to hunt bets with his friends. Carlos and Camila are two of them. Nicolás estimates that the next bet will be made with Carlos with a triple probability than he will do with Camila. If he faces Carlos, they will play 2 times, while if he faces Camila, they will play 3 times. In each bet, Nicolás pays $ 1.5...
One of the most popular games of chance is a dice game known as “craps”, played...
One of the most popular games of chance is a dice game known as “craps”, played in casinos around the world. Here are the rules of the game: A player rolls two six-sided die, which means he can roll a 1, 2, 3, 4, 5 or 6 on either die. After the dice come to rest they are added together and their sum determines the outcome. If the sum is 7 or 11 on the first roll, the player wins....
[15 marks] Draw the flowchart of the following programming problem: You can draw the flowchart using...
[15 marks] Draw the flowchart of the following programming problem: You can draw the flowchart using a drawing tool, or draw the flowchart on a piece of paper, take a picture, insert it here or save it in the submission folder The program randomly generates an integer between 0 and 100, inclusive. The program prompts the user to enter a number continuously until the number matches the randomly generated number. For each user input, the program tells the user whether...
Write a program that allows two players to play a game of tic-tac-toe. Use a twodimensional...
Write a program that allows two players to play a game of tic-tac-toe. Use a twodimensional char array with three rows and three columns as the game board. Each element in the array should be initialized with an asterisk (*). The program should run a loop that: • Displays the contents of the board array. • Allows player 1 to select a location on the board for an X. The program should ask the user to enter the row and...
Write a program to pre-sell a limited number of cinema tickets. Each buyer can buy as...
Write a program to pre-sell a limited number of cinema tickets. Each buyer can buy as many as 4 tickets. No more than 20 tickets can be sold. Implement a program called TicketSeller that prompts the user for the desired number of tickets and then displays the number of remaining tickets. Repeat until all tickets have been sold, and then display the total number of buyers.4 pts Loop     There are currently xxx tickets remaining.     How many tickets would...