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
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.
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...
[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...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
I am making a game like Rock Paper Scissors called fire water stick where the rules...
I am making a game like Rock Paper Scissors called fire water stick where the rules are Stick beats Water by floating on top of it Water beats Fire by putting it out Fire beats Stick by burning it The TODOS are as follows: TODO 1: Declare the instance variables of the class. Instance variables are private variables that keep the state of the game. The recommended instance variables are: 1. 2. 3. 4. 5. 6. A variable, “rand” that...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From the April 2004 Issue Save Share 8.95 In 1991, Progressive Insurance, an automobile insurer based in Mayfield Village, Ohio, had approximately $1.3 billion in sales. By 2002, that figure had grown to $9.5 billion. What fashionable strategies did Progressive employ to achieve sevenfold growth in just over a decade? Was it positioned in a high-growth industry? Hardly. Auto insurance is a mature, 100-year-old industry...