Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with a rock, paper, and scissor program in C++ language. Here is the

ID: 3664244 • Letter: I

Question

I need help with a rock, paper, and scissor program in C++ language.

Here is the question:

Write a program to score the paper-rock-scissor game. Each of the two users types in ether P, R, or S. The program then announces the winner as well as the basis for determining the winner: Paper covers rock, Rock brakes scissors, Scissors cut paper, or Nobody wins. Be sure to allow the users to use lowercase as well as uppercase letters. Your program should include a loop that lets the user play again until the user says she or he is done.

Here is my code:

#include <iostream>
using namespace std;

int main( )
{
// Variables declaration.
   char user1;
   char user2;
   char choice;
  
// Repeat the loop until the player exits the game.
   do
   {
// Prompt user 1 to enter their choice.
       cout << "Enter either P)aper, R)ock, or S)cissors for player number 1: ";
       cin >> user1;
      
// Prompt user 2 to enter thier choice.
       cout << "Enter either P)aper, R)ock, or S)cissors for player number 2: ";
       cin >> user2;
      
// Display an error message if any of the users enters an invalid choice.
// Verify whether the choices entered by the players are valid.
       if(user1 != 'P' && user1 != 'p'
       && user1 != 'R' && user1 != 'r'
       && user1 != 'S' && user1 != 's'
       && user2 != 'P' && user2 != 'p'
       && user2 != 'R' && user2 != 'r'
       && user2 != 'S' && user2 != 's')
       {
// Print an error message.
           cout << "Invalid choice!" << endl;
       }
// Verify whether the player 1 choose the papper.
       else if(user1 == 'P' || user1 == 'p')
       {
// Verify whether the player 2 chooses the rock.
           if(user2 == 'R' || user2 == 'r');
           {
               cout << "Paper covers rock." << endl;
               cout << "User 1 wins the game." << endl;
           }
// Verify whether the player 2 chooses the scissors.
       else if(user2 == 'S' || user2 == 's')
           {
               cout << "Scissors cut paper." << endl;  
               cout << "Player 2 wins the game." << endl;
           }
// If both the plyers choose paper.
       else
           {
               cout << "Nobody wins the game." << endl;
           }
       }
// Verify whether the player 1 choose rock.
       else if(user1 == 'R' || user1 == 'r')
       {
// Verify whether play 2 chooses the scissors.
           if(user2 == 'S' || user2 == 's')
           {
               cout << "Rock breaks scissors." << endl;
               cout << "Player 1 wins the game." << endl;
           }
// Verify wether player 2 chooses the paper.
       else if(user2 == 'P' || user2 == 'p')
       {
           cout << "Paper covers rock." << endl;
           cout << "Player 2 wins the game." << endl;
       }
// If both players choose rock.
       else
           {
               cout << "Nobody wins the game." << endl;
           }
       }
// If the player 1 chooses the scissors
       else if(user1 == 'S' || user1 == 's')
       {
// Verify whether player 2 chooses the paper.
           if(user2 == 'P' || user2 == 'p')
           {
               cout << "Scissors cut paper." << endl;
               cout << "Player 1 wins the game." << endl;
           }
// Verify whether the user 2 choose the rock.
       else if(user2 == 'R' || user2 == 'r')
       {
           cout << "Rock breaks scissors." << endl;
           cout << "Player 2 wins the game." << endl;
       }
// If both players choose scissors.
       else
       {
           cout << "Nobody wins the game." << endl;
       }
       }
// Prompt the player's choice to play the game agian.
       cout << "Enter Y/y to play game again: ";
       cin >> choice;
       cout << endl;
      
       }while(choice == 'Y' || choice == 'y');
// Pause the system for a while
       system("pause");
      
       return0;
          
      
}

Can anybody tell me what I am doing worng?

Explanation / Answer

program

*/

//System Libraries
#include <iostream> //I/O
using namespace std;


//Execution Begins Here
int main(int argc, char** argv)
{
  
    //Declaring and initializing variables of the two users and if they would like to repeat the game.
    char user1;//Input from user 1
    char user2;//Input from user 2
    char choice;//Decision if they would like to play again
  
    //Do while loop to determine if the users would like to play again.
    do
    {
        //The problem to solve
        cout<<"This program will be a game of rock, paper, scissors between two users."<<endl;
        cout<<"Select which player will be user 1 and which will be user 2."<<endl<<endl;
      
        //First user inputs their choice of rock,paper, or scissors
        cout<<"User 1 please write you choice for Rock, Paper, or Scissor using ";
        cout<<"the characters R, P, or S."<<endl;
        cin>>user1;
        user1=toupper(user1);
      
        //Second user inputs their choice of rock, paper, or scissors
        cout<<"User 2 please write you choice for Rock, Paper, or Scissor using ";
        cout<<"the characters R, P, or S."<<endl;
        cin>>user2;
        user2=toupper(user2);
      
        //If else loop to determine based on inputs who won/output of results
        if (user1==user2)
        {
            cout<<"You both tied, therefore nobody wins!"<<endl;
        }
        else if (user1=='P'&&user2=='R')
        {
            cout<<"Paper covers rock, therefore user 1 wins!"<<endl;
        }
        else if (user1=='R'&&user2=='P')
        {
            cout<<"Paper covers rock, therefore user 2 wins!"<<endl;
        }
        else if (user1=='S'&&user2=='R')
        {
            cout<<"Rock breaks scissors, therefore user 2 wins!"<<endl;
        }
        else if (user1=='R'&&user2=='S')
        {
            cout<<"Rock breaks scissors, therefore user 1 wins!"<<endl;
        }
        else if (user1=='S'&&user2=='P')
        {
            cout<<"Scissors cuts paper, therefore user 1 wins!"<<endl;
        }
        else if (user1=='P'&&user2=='S')
        {
            cout<<"Scissors cuts paper, therefore user 2 wins!"<<endl;
        }
      
        //Asks the users if they would like to play again
        cout<<"Would you like to play the game again?"<<endl;
        cout<<"Type y for yes or anything else to exit the program."<<endl;
        cin>>choice;
      
    }while(toupper(choice)=='Y');

    //Exit stage right
    return 0;
}

output

                                         
This program will be a game of rock, paper, scissors between two users.                                                                                     
Select which player will be user 1 and which will be user 2.                                                                                                
                                                                                                                                                            
User 1 please write you choice for Rock, Paper, or Scissor using the characters R, P, or S.                                                                 
R                                                                                                                                                           
User 2 please write you choice for Rock, Paper, or Scissor using the characters R, P, or S.                                                                 
P                                                                                                                                                           
Paper covers rock, therefore user 2 wins!                                                                                                                   
Would you like to play the game again?                                                                                                                      
Type y for yes or anything else to exit the program.                                                                                                        
N                                                                                                                                                           

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote