Kat H.

asked • 05/24/21

RPS Enumeration. Use the given enumerations to write a function Result getResult(Choice player1, Choice player2) .

Use the given enumerations to write a function Result getResult(Choice player1, Choice player2) . It should determine the winner of a round of Rock, Paper, Scissors between two players (Rock beats Scissors, Scissors beats Paper and Paper beats Rock). Return WIN if player1 wins, LOSE if player1 loses or DRAW if there is no winner.


Code:


#include <iostream>


using namespace std;


//Lose =-1, Draw = 0, Win = 1

enum Result { LOSE = -1, DRAW, WIN };


enum Choice { ROCK, PAPER, SCISSORS };

//Do not modify anything on or above the line below this

//YOUR_CODE_BELOW


//YOUR_CODE


//YOUR_CODE_ABOVE

//Do not modify anything on or below the line above this


int main()

{

Result result1 = getResult( ROCK, PAPER );

cout << result1 << endl;

Result result2 = getResult( ROCK, SCISSORS );

cout << result2 << endl;

Result result3 = getResult( ROCK, ROCK );

cout << result3 << endl;

Result result4 = getResult( PAPER, PAPER );

cout << result4 << endl;

Result result5 = getResult( PAPER, SCISSORS );

cout << result5 << endl;

Result result6 = getResult( PAPER, ROCK );

cout << result6 << endl;

Result result7 = getResult( SCISSORS, PAPER );

cout << result7 << endl;

Result result8 = getResult( SCISSORS, SCISSORS );

cout << result8 << endl;

Result result9 = getResult( SCISSORS, ROCK );

cout << result9 << endl;

}

1 Expert Answer

By:

Patrick B. answered • 05/24/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.