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...
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...
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...
in the scheme programming language implement a game of rock paper scissors between a user and...
in the scheme programming language implement a game of rock paper scissors between a user and the computer. Only the following scheme subsets should be used: Special symbols (not case sensitive in our version (R5RS), but is in R6RS): a. Boolean: #t (else) and #f b. Characters: #\a, #\b ... #\Z c. Strings: in double quotes 3. Basic functions: a. quote b. car c. cdr d. c _ _ _ _ r, where each _ is either “a” or “d”...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • 1. Construct an explicit bijection between the following sets. Once you've done that, construct injections going...
    asked 33 minutes ago
  • What Is Power? The Trial Urban District Assessment (TUDA) measures educational progress within participating large urban...
    asked 1 hour ago
  • Create a Client/Server program in C language
    asked 1 hour ago
  • USING C++ Topics: Friend functions Copy constructor ----------------------------------------------------------------------------------------------------------------------------------------- Lab 3.1 Create your objects in the stack...
    asked 1 hour ago
  • •discuss the following and their uses in computers and engineering: Integrated circuits and use of pins
    asked 2 hours ago
  • Do you believe you should vote for a political candidate based solely on race or gender?...
    asked 2 hours ago
  • Service Department Charges and Activity Bases Harold Corporation, a manufacturer of electronics and communications systems, uses...
    asked 2 hours ago
  • A financial analyst has determined that there is a 22% probability that a mutual fund will...
    asked 2 hours ago
  • What does Buddhism mean by "self does not exist"?
    asked 2 hours ago
  • Give formal definition of the regular language generated by the following Regular Expressions: 1) ((ab*+a)*+ab) 2)...
    asked 3 hours ago
  • In a recent​ year, a poll asked 2184 random adult citizens of a large country how...
    asked 3 hours ago
  • Science writer Judith Stone wrote, ‘There are two ways to approach a subject that frightens you...
    asked 3 hours ago