Rock-Paper-Scissors This program should score one game of the rock-paper-scissor
ID: 3640556 • Letter: R
Question
Rock-Paper-ScissorsThis program should score one game of the rock-paper-scissors game, which is where each player picks either rock, paper, or scissors, and then one of the following happens:
Rock dulls scissors
Paper covers rock
Scissors cut paper
There is a tie (both players picked the same thing)
The user may enter either 'r' or 'R' for Rock.
The user may enter either 'p' or 'P' for Paper.
The user may enter either 's' or 'S' for Scissors.
If the user enters invalid input, your program should say so, otherwise it will output one of the above results.
Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
char p1,p2;
int c;
do
{
cout<<"Player 1 enter your choice: ";
cin>>p1;
p1=tolower(p1);
if(p1=='r'||p1=='p'||p1=='s')c=0;else {
c=1; cout<<"Wrong choice enter again: ";}
}while(c);
do
{
cout<<"Player 2 enter your choice: ";
cin>>p2;
p2=tolower(p2);
if(p2=='r'||p2=='p'||p2=='s')c=0;else{
c=1;cout<<"Wrong choice enter again: ";}
}while(c);
if(p1==p2)cout<<" There is a tie (both players picked the same thing) ";
if(p1=='r' && p2=='p')cout<<"Paper covers rock ,player 2 wins";
if(p1=='p' && p2=='r')cout<<"Paper covers rock ,player 1 wins";
if(p1=='p' && p2=='s')cout<<"Scissors cut paper ,player 2 wins";
if(p1=='s' && p2=='p')cout<<"Scissors cut paper ,player 1 wins";
if(p1=='r' && p2=='s')cout<<"Rock dulls scissors ,player 1 wins";
if(p1=='s' && p2=='r')cout<<"Rock dulls scissors ,player 2 wins";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.