Rock Paper Scissors game help!

I currently have an almost finished program of Rock Paper Scissors, sepereated into 4 functions, I can get the players choice and the computer choice to print out I just need it to print out who wins and i need it to ask how many games of RPS you want to play, odd of course, then output the winner of the Game much like tennis.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;


int readAndValidateUserMove()
{
    char move;

    do {

    cout << "Please enter your choice (r, p, s): ";
    cin >> move;
    cout << "You entered: " << move << endl;

    } while ((move !='R')&&(move !='r')&&(move !='P')&&(move !='p')&&(move !='s')&&(move != 'S'));
    if(move == 'r' || move == 'R')
    {
        move = 0;
    }
    else if(move == 'p' || move == 'P')
    {
        move = 1;
    }
    else if(move == 's' || move == 'S')
    {
        move = 2;
    }
}
int computerMove()
{
   srand(time(0));
   char compChoice = rand() % 3;
   if (compChoice == 0)
   {
      cout << "The computer chose Rock" << endl;
   }
   if (compChoice == 1)
   {
      cout << "The computer chose Paper" << endl;
   }
   if (compChoice == 2)
   {
      cout << "The computer chose Scissors" << endl;
   }

}

int gameOutcome(int playerChoice, int compChoice)
{
   if (playerChoice == '0' && compChoice == '0')
   {
      cout << "Tie game\n";
   }
   else if (playerChoice == '0' && compChoice == '1')
   {
       cout << "Computer wins\n";
   }
   else if (playerChoice == '0' && compChoice == '2')
   {
       cout << "Player wins\n";
   }
   else if (playerChoice == '1' && compChoice == '0')
   {
       cout << "Player wins\n";
   }
   else if (playerChoice == '1' && compChoice == '1')
   {
       cout << "Tie game\n";
   }
   else if (playerChoice == '1' && compChoice == '2')
   {
       cout << "Computer wins\n";
   }
   else if (playerChoice == '2' && compChoice == '0')
   {
       cout << "Computer wins\n";
   }
   else if (playerChoice == '2' && compChoice == '1')
   {
       cout << "Player wins\n";
   }
   else if (playerChoice == '2' && compChoice == '2')
   {
       cout << "Tie game\n";
   }
   cout << endl;
}

int main()
{
    int playerChoice;
    int compChoice;
    int totalOutcome;

    playerChoice = readAndValidateUserMove();
    compChoice = computerMove();
    totalOutcome = gameOutcome(playerChoice, compChoice);


    return 0;
}
Last edited on
The functions playerChoice and compChoice don't return any anything. Also, assuming that totalOutcome stores the number of times the player has won, gameOutcome should also return 1 for win and 0 for loss. Then you can add the returned value to totalOutcome.

As for having a set number of rounds, you can ask the player for a value, check if it's odd using mod, and then have the code in a for loop. To check who won, you can use

1
2
3
if (totalOutcome > (numberOfRounds - 1) / 2) {
    // code
}


Hope this helps.
Last edited on
Topic archived. No new replies allowed.