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

Hello i need help with a C++ program i need a c++ program to run a rock paper sc

ID: 3576000 • Letter: H

Question

Hello i need help with a C++ program i need a c++ program to

run a rock paper scissors program, that allows the user to choose either rock paper or scissors and play against the computer, adding text to inform the user if she has lost or won. I also need the user to be asked if they would like to play the game again after every game so that the game itself can be played multiple times. Allow the user to play as many times as they like, as long as they continue to reply in the affirmative.

please provide source code

thank you

Explanation / Answer

As per the requirements, the code is:

Code:

#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
char again;

char userinput, compchoice;

int compgennumber;

cout << "Rock Paper Scissor Game: " << endl;
cout << "Type r for rock, p for paper, s for scissor" << endl;

do
{
cout << endl << "Enter your input: ";
cin >> userinput;

compgennumber = rand()%3;

compchoice = (compgennumber==0)?'R':(compgennumber==1)?'P':'S';

cout << "Computer selected " << compchoice << endl;

if(userinput == 'R' || userinput == 'r')
{
if(compchoice == 'R' || compchoice == 'r')
cout << "Tie";

else if(compchoice == 'S' || compchoice == 's')
cout << "You win";

else
cout << "You lose";
}

else if(userinput == 'P' || userinput == 'p')
{
if(compchoice == 'P' || compchoice == 'p')
cout << "Tie";

else if(compchoice == 'R' || compchoice == 'r')
cout << "You win";

else
cout << "You lose";
}

else if(userinput == 'S' || userinput == 's')
{
if(compchoice == 'S' || compchoice == 's')
cout << "Tie";

else if(compchoice == 'P' || compchoice == 'p')
cout << "You win";

else
cout << "You lose";
}

else
{
cout << "Invalid input.";
}

cout << endl << endl;

cout << "Play again? (Y or N): ";

cin >> again;
}

while(again =='Y' || again == 'y');
return 0;
}

Note: You can play it multile times till user relies affirmative, plus it handles both uppercase and lowercase inputs. :)

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