Rock Paper Scissors Lizard Spock

Im writing the basic RPS program but I have to add in a twist. After writing the code it builds but the computer will not chose, Im not sure what I'm missing.
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

void ShowProgramHeader();
int main()
{
    int PlayerChoice;
    
    void Intro();
    {
        
        
        
        cout <<" Welcome to Rock, Paper, Scissors, Lizard, Spock " << endl;
        cout <<" " << endl;
        cout <<" Rules of the game : " << endl;
        cout <<" Scissors cuts Paper covers Rock crushes Lizard poisons Spock smashes" << endl;
        cout <<" Scissors decapitates Lizard eats Paper disproves Spock vaporizes Rock crushes" << endl;
        cout <<" Scissors " << endl;
        cout <<" " << endl;
        cout <<" Please choose your choice: 1 = Rock, 2 = Paper " << endl;
        cout <<" 3 = Scissors, 4 = Lizard, 5 = Spock " << endl;
        
        cin >> PlayerChoice;
        
    }
    
    if ( PlayerChoice == 1 )
    {
        
        
        cout <<" Player Chooses: Rock " << endl;
    }
    
    else if ( PlayerChoice == 2 )
    {
        
        cout <<" Player Chooses: Paper " << endl;
    }
    
    else if ( PlayerChoice == 3 )
    {
        
        cout <<" Player Chooses: Scissors " << endl;
    }
    
    else if ( PlayerChoice == 4 )
    {
        
        cout << " Player Chooses: Lizard " << endl;
    }
    
    else if ( PlayerChoice == 5 )
    {
        
        cout << " Player Chooses: Spock " << endl;
        
        return PlayerChoice;
    }
    
    int CompChoice;
    
    
    srand(time(0));
    
    CompChoice = rand() % 5 + 1;
    
    if ( CompChoice == 1 )
    {
        CompChoice = '1';
        cout << " Computer Chooses: Rock " << endl;
    }
    
    else if ( CompChoice == 2 )
    {
        CompChoice = '2';
        cout << " Computer Chooses: Paper " << endl;
    }
    
    else if ( CompChoice == 3 )
    {
        CompChoice = '3';
        cout << " Computer Chooses: Scissors " << endl;
    }
    
    else if ( CompChoice == 4 )
    {
        CompChoice = '4';
        cout << " Computer Chooses: Lizard " << endl;
    }
    else if ( CompChoice == 5 )
    {
        CompChoice = '5';
        cout << " Computer Chooses: Spock " << endl;
        
        return CompChoice;
    }
    
    if ( ( PlayerChoice == 1 && CompChoice == 1 ) ||
        ( PlayerChoice == 2 && CompChoice == 2 ) ||
        ( PlayerChoice == 3 && CompChoice == 3 ) ||
        ( PlayerChoice == 4 && CompChoice == 4 ) ||
        ( PlayerChoice == 5 && CompChoice == 5 ) )
    {
        cout << " It's a TIE! " << endl;
    }
    
    else if (( PlayerChoice == 3 && CompChoice == 2 ) ||
             ( PlayerChoice == 2 && CompChoice == 1 ) ||
             ( PlayerChoice == 1 && CompChoice == 4 ) ||
             ( PlayerChoice == 4 && CompChoice == 5 ) ||
             ( PlayerChoice == 5 && CompChoice == 3 ) ||
             ( PlayerChoice == 3 && CompChoice == 4 ) ||
             ( PlayerChoice == 4 && CompChoice == 2 ) ||
             ( PlayerChoice == 2 && CompChoice == 5 ) ||
             ( PlayerChoice == 5 && CompChoice == 1 ) ||
             ( PlayerChoice == 1 && CompChoice == 3 ))
    {
        cout << " Congratulations, You have WON! " << endl;
    }
    
    else if (( PlayerChoice == 2 && CompChoice == 3 ) ||
             ( PlayerChoice == 1 && CompChoice == 2 ) ||
             ( PlayerChoice == 4 && CompChoice == 1 ) ||
             ( PlayerChoice == 5 && CompChoice == 4 ) ||
             ( PlayerChoice == 3 && CompChoice == 5 ) ||
             ( PlayerChoice == 4 && CompChoice == 3 ) ||
             ( PlayerChoice == 2 && CompChoice == 4 ) ||
             ( PlayerChoice == 5 && CompChoice == 2 ) ||
             ( PlayerChoice == 1 && CompChoice == 5 ) ||
             ( PlayerChoice == 3 && CompChoice == 1 ))
    {
        cout << " Too Bad, You have LOST! " << endl;
    }
    
    
    return 0;
What do you mean by "the computer will not choose"? Does it turn itself off? Does it close all your programs? Does it take the both the red and blue pills? You need to be more specific.
A few things I see...

You're calling a function void Intro(); but I don't see that defined in what you've posted so far?

You have returns for PlayerChoice or CompChoice in the condition that either the player or computer chooses the fifth option. Were these if/else statements supposed to be in a separate function from the main function?

CompChoice = '1'
Since this is defined as an integer variable, I would put CompChoice=1. (not '1' as in a character)
void Intro(); shouldn't be in main. Move it before main and then call it with Intro(). I'm also new to coding, and I've found that the 'or' statement (||) can be unreliable (at least when I've used it). If all else fails, maybe change all the or statements into separate else if statements?
Last edited on
70
71
72
73
74
if ( CompChoice == 1 )
{
    CompChoice = '1';
    cout << " Computer Chooses: Rock " << endl;
}

I don't see the point in assigning a new value to compChoice like this.
And in fact, when I remove those lines, it seems to work fine for me...
Topic archived. No new replies allowed.