Write a program to score the paper-rock-scissor game. Each of two users types in either P, R, or S. 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 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.
Program:
#include<iostream>
Using namespace STD;
void main()
{
char choice1, choice2,choice,userChoice;
do
{ for(int i = 0; i<2; i++)
{
do
{
cout<<" Enter your choice P, R or S:";
cin>>choice;
}while(choice != 'p' && choice !='P' && choice != 'r'
&& choice !='R' && choice !='S' && choice!='s');
if(i == 0)
{
choice1= choice;
}
else if(i ==1)
{
choice2 = choice;
}
}
if(choice1 == choice2)
{
cout<<" Game has ended in a draw\n";
}
else
{
if(choice1 == 'p' || choice1 =='P')
{
if (choice2 =='s' || choice2 =='S')
{
cout<<" As scissor can cut paper player 2 win \n";
}
else
{
cout<<" As paper cover rock, player 1 wins \n";
}
}
if(choice1 == 's' || choice1 =='s')
{
if (choice2 =='p' || choice2 =='p')
{
cout<<" As scissor can cut paper player 1 win\n";
}
else
{
cout<<"As rock can break scissor ,
player 2 wins\n";
}
}
if(choice == 'r' || choice1 =='r')
{
if (choice2 =='s' || choice2 =='S')
{
cout<<"As rock can break scissor player 1 wins";
}
else
{
cout<<"As paper cover rock, player 2 wins";
}
}
}
cout<<"\n To repeat calculations for
different variables then press 'y' or 'Y'\n ";
cin>>userChoice;
}while(userChoice =='y' || userChoice =='Y');
}
Output:
Enter your choice P, R or S:r
Enter your choice P, R or S:p
As paper cover rock, player 2 wins
To repeat calculations for different variables then press 'y' or 'Y': n