Rock Paper Scissor is a hand game played between two people. Write a C++ program to implement this game using the conditional statements.
Rules of the game
- Rock crushes Scissor
- Paper covers Rock
- Scissor cuts Paper
#include<iostream>
using namespace std;
int main(){
cout<<"ROCK(1) PAPER(2) SCISSOR(3)"<<endl;
int choice1,choice2;
enum choice{ROCK=1,PAPER=2,SCISSOR=3};
cout<<"Enter your choice"<<endl;
cout<<"Player 1 : ";
cin>>choice1;
cout<<"Player 2 : ";
cin>>choice2;
if(choice1==choice2){
cout<<"Draw"<<endl;
}
else if(choice1==ROCK){
if(choice2==PAPER) cout<<"Player 2 wins"<<endl;
else cout<<"Player 1 wins"<<endl;
}
else if(choice1==PAPER){
if(choice2==ROCK) cout<<"Player 1 wins"<<endl;
else cout<<"Player 2 wins"<<endl;
}
else{
if(choice2==ROCK) cout<<"Player 2 wins"<<endl;
else cout<<"Player 1 wins"<<endl;
}
return 0;
}
