113k views
5 votes
Design a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Don’t display the computer’s choice yet.) The user enters his or her choice of "rock," "paper," or "scissors" at the keyboard. The computer’s choice is displayed. The program should display a message indicating whether the user or the computer was the winner. A winner is selected according to the following rules: If one player chooses rock and the other player chooses scissors, then rock wins. (The rock smashes the scissors.) If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors cut paper.) If one player chooses paper and the other player chooses rock, then paper wins. (Paper wraps rock.) If both players make the same choice, the game must be played again to determine the winner. starting out with programming logic and design

User Cam Song
by
4.7k points

1 Answer

3 votes

Answer:

switch (object)

{

case Rock: cout << "Rock";

break;

case Paper: cout << "Paper";

break;

case Scissors: cout << "Scissors";

}

}

objectType winningObject(objectType plat1, objectTypeplay2)

(play2 == Rock && play1 == Paper))

return Paper;

else

return Scissors;

void gameResult(objectType play1, objectType play2, int&winner)

{

onjectType winnerOnject;

if (play1 == play2)

{

winner = 0;

cout<< "Both players selected ";

convertEnum(play1);

cout << ". This game is a tie." << endl;

}

else

{

winnerObject = winningObject(play1,play2);

//Output each player's choice

cout << "Player 1 selected ";

convertEnum(play1);

cout << " and player 2 selected ";

convertEnum(play2);

cout <<".";

//Decide the winner

if (play1 == winnerObject)

winner = 1;

else if (play2 == winnerObject)

winner = 2;

//Output the winner

cout << "Player " << winner << " wins thisgame." << endl;

}

}

void displayResults(int gCout, int wCountll, intwCount2)

{

cout << "The total number of plays: " << gCount<< endl;

cout << "The number of plays won by player 1: " <<wCountl << endl;

cout << "The number of plays won by player 2: " <<wCount2 << endl;

}

User SebHallin
by
5.0k points