Question

In: Computer Science

Write a C++ program to score the paper-rock-scissor game. Each of two players (player1 and player2)...

Write a C++ program to score the paper-rock-scissor game. Each of two players (player1 and player2) input a character which could be either ‘P’, ‘R’, or ‘S’ (in uppercase or lowercase). For any other input character should display a message “Invalid input”. The program then announces who is the winner as well as the basis for determining the winner which could be one of the following: “Paper covers rock”, “Rock breaks scissors”, “Scissors cut paper”, or “Nobody wins”. (Use switch statement)

Please do not add up the scores just have a simple quick game and then I would have to reset the program to play again

Solutions

Expert Solution

#include <iostream>
#include <string>
#include <cstdlib>      //rand()
#include <ctime>        //time()
using namespace std;

int main(){
  
  int randNumber;
  string input, rock, paper, scissor;
  
  cin >> input;
    
    if(input=="rock"||input=="paper"||input=="scissor"){
        
        cout << "Type in: rock, paper or scissor:\n" <<endl;
        cout << " " << endl;
        
        //Random number by help of time
        srand( unsigned (time(0)));            
  
        //random number betw 1 & 3
        randNumber=rand()%3+1;      
        
        if(input == "rock"){   
            
            switch (randNumber){    
                case 1:
                cout<<"rock vs rock\n"<<endl;
                cout<<"*****DRAW*****";
                break;
        
                case 2:
                cout<<"rock vs paper\n"<<endl;
                cout<<"*****You LOSE*****"; 
                break;
        
                case 3:
                cout<<"rock vs scissor\n"<<endl;
                cout<<"*****You WON*****";
                break;
            }
        }
        
        else if(input == "paper"){
            
             switch (randNumber){
                case 1:
                cout<<"paper vs paper\n"<<endl;
                cout<<"*****DRAW*****";
                break;
                
                case 2:
                cout<<"paper vs scissor\n"<<endl;
                cout<<"*****You LOSE*****";
                break;
                
                case 3:
                cout<<"paper vs rock\n"<<endl;
                cout<<"*****You WON*****";
                
            }
        }
        
        else if(input == "scissor"){
            
            switch(randNumber){
                case 1:
                cout<<"scissor vs scissor\n"<<endl;
                cout<<"*****It's a DRAW*****";
                break;
                
                case 2:
                cout<<"scissor vs rock\n"<<endl;
                cout<<"*****You LOSE*****";
                break;
                
                case 3:
                cout<<"scissor vs paper\n"<<endl;
                cout<<"*****You WON*****";
                break;
            }
        }
    }   
   
    else{
        cout<<"You typed:    "<<input<<endl;
        cout<<" "<<endl;
        cout<<"That's not correct.\n"<<endl;
        cout<<"Type in; rock, paper or scissor.";
    }
    
    return 0;
}

Related Solutions

Write a C++ program to score the paper-rock-scissor game. Each of two players (player1 and player2)...
Write a C++ program to score the paper-rock-scissor game. Each of two players (player1 and player2) input a character which could be either ‘P’, ‘R’, or ‘S’ (in uppercase or lowercase). For any other input character should display a message “Invalid input”. The program then announces who is the winner as well as the basis for determining the winner which could be one of the following: “Paper covers rock”, “Rock breaks scissors”, “Scissors cut paper”, or “Nobody wins”. (Use switch...
Java) Write a program to score the rock-paper-scissor game. Each of two users types in either...
Java) Write a program to score the rock-paper-scissor game. Each of two users types in either R, P, S or Q to quit. The program then announces the winner as well as the basis for determining the winner: Paper covers rock, Rock breaks scissors, Scissors cut paper, or a Tie game. Allow the user to use lowercase as well as uppercase letters. Your program should loop until the user types a 'Q' to quit. In the sample code, the game...
Subjects: Write a Python program that allows users to play the popular rock-paper-scissor game against the...
Subjects: Write a Python program that allows users to play the popular rock-paper-scissor game against the computer multiple times. This program assesses your knowledge of decision structures, repetition structures, and functions. Requirements: 1.Define a function named as play_game. This function receives two parameters representing the player’s and computer’s choices, and it returns an integer representing the game result from the player’s perspective. Specifically, it returns 1 if the player wins and 0 if the player does not win. Hint: you...
JAVA Remember the childhood game “Rock, Paper, Scissors”? It is a two-players game in which each...
JAVA Remember the childhood game “Rock, Paper, Scissors”? It is a two-players game in which each person simultaneously chooses either rock, paper, or scissors. Rock beats scissors but loses to paper, paper beats rock but loses to scissors, and scissors beats paper but loses to rock. Your program must prompt the player 1 and player 2 to each enter a string for their choice: rock, paper, or scissors. Then appropriately reports if “Player 1 wins”, “Player 2 wins”, or “It...
JAVA PROGRAM, Create the game "Rock, Scissor, Paper": Make the AI pick randomly. You need to...
JAVA PROGRAM, Create the game "Rock, Scissor, Paper": Make the AI pick randomly. You need to look up Random numbers in Java. First ask the user what language they want to play in. Choice 1 is English, but choice 2 can be whatever real language you want. Your first loop is making sure they enter good input. If there is a tie you don't give them the option to play again. They have to. Outer loop runs until they say...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper,...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows: • Rock beats scissors, because a rock can break a pair of scissors. • Scissors beats paper, because scissors can cut paper. • Paper beats rock, because a piece of paper can cover a rock. Create a game...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper,...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows: • Rock beats scissors, because a rock can break a pair of scissors. • Scissors beats paper, because scissors can cut paper. • Paper beats rock, because a piece of paper can cover a rock. Create a game...
Background: In the game “Rock, Paper, and Scissors,” two players simultaneously say (or display a hand...
Background: In the game “Rock, Paper, and Scissors,” two players simultaneously say (or display a hand symbol representing) either “rock,” “paper,” or “scissors.” The winner is the one whose choice wins over the other. The rules are: paper wins over (wraps) rock, rock wins over (breaks) scissors, and scissors wins over (cuts) paper. Assignment: A customer wants you to design and implement a program (RPS.py) for playing the game of “Rock, Paper, Scissors” for a single player against the computer....
Write a Java program that plays the game Rock, Paper, Scissors. The program should generate a...
Write a Java program that plays the game Rock, Paper, Scissors. The program should generate a random choice (Rock, Paper or Scissors) then ask the user to choose Rock, Paper or Scissors. After that the program will display its choice and a message showing if the player won, lost or tied. Next, the program should prompt the user to play again or not. Once the player selects to stop playing the game, the program should print the number of wins,...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: You can set these constant global variables at the top outside of your main function definition: COMPUTER_WINS = 1 PLAYER_WINS = 2 TIE = 0 INVALID = 3 ROCK = 1 PAPER = 2 SCISSORS = 3 For this program 1 represents rock, 2 represents paper, and 3 represents scissors. In...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT