Guys please can you help me with this question ?
Write a program that plays the game of “Rock, Paper, and Scissors.” In this game, two players simultaneously say (or display a hand symbol representing) either “rock,” “paper,” or “scissors.” The winner is the one whose choice dominates the other.
The rules are: paper dominates (wraps) rock, rock dominates (breaks) scissors, and scissors dominate (cut) paper.
The game has only three possible outcomes other than a tie: a player who decides to play rock will beat another player who has chosen scissors ("rock crushes scissors") but will lose to one who has played paper ("paper covers rock"); a play of paper will lose to a play of scissors ("scissors cut paper"). If both players throw the same shape, the game is tied.
You will enter two text data in two lines as players choices; -In the first line you will enter first player’s choice. -In the following line second player’s choice will be entered.
Your program should display an output as “Player1 wins” , “Player2 wins” or “You tied”.
Rock Scissors Paper
Post a Reply
|Oldest Newest Rating|
· December 10, 2015
Well, first of all, don't really see the point of the both players playing from the same computer...it is not really simultaneous....it would be better to make a program so that each players plays from his own PC...so that they don't see each others choice.
But...if you want to do this just for practice...you could attribute each choice to a number (rock-1, paper-2, scissors-3).
On the screen a similar message will be displayed : 'Choose: 1-rock , 2-paper, 3-scissors', and each player must input a number.
After both players have inputed their number, I suggest you can concatenate these two numbers (change them back to int type with cast, or something similar).
You can have a method with a case similar to this:
case 11: return 'tie'
case 12: return 'player 2 wins' (player 1 chose rock, player two chose paper)
case 13: return 'player 1 wins' (....)
case 33: return 'tie'
Hope you get the point...
This method is ok because there are pretty few options.
· December 11, 2015
Thank you @Ovdiu Pocnet,
I solved it like this
using namespace std;
int cnt1=0, cnt2=0;
if(type1=="Rock" && type2=="Paper") cnt2++;
if(type1=="Rock" && type2=="Scissors") cnt1++;
if(type1=="Paper" && type2=="Rock") cnt1++;
if(type1=="Paper" && type2=="Scissors") cnt2++;
if(type1=="Scissors" && type2=="Paper") cnt1++;
if(type1=="Scissors" && type2=="Rock") cnt2++;
if(cnt1>cnt2) cout<<"\nPlayer1 wins"<<endl;
if(cnt1<cnt2) cout<<"\nPlayer2 wins"<<endl;
if(cnt1==cnt2) cout<<"\nYou tied"<<endl;
One of the most popular languages of all time.
|Bucky Roberts Administrator|