Help: Rock, Paper Scissors Game

Here's the assignment:
http://www.rdb3.com/python/exercises/7.8.pdf

I dont know what im doing wrong.

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
 #include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
    int number,usernumber = 0;
    char userpick;
    int userscore,compscore;
    userscore=0;
    compscore=0;
    
    
        
        srand(time(0));
        number = 1 + (rand() % 3) ;
        
        cout<<"Choose: [Rock, Paper, Scissors or Quit]: ";
        cin>>userpick;
        
        if(userpick=='r'|| userpick=='R')
        {
            usernumber=1;
        }
        if(userpick=='p'|| userpick=='P')
        {
            usernumber=2;
        }
        if(userpick=='s'|| userpick=='S')
        {
            usernumber=3;
        }
        if(userpick=='q'|| userpick=='Q')
        {
            usernumber=4;
        }
    
    
        if(usernumber==number)
        {
            cout<<"Computers: " <<userpick<< ", Human: "<<userpick<< ", Tie" << endl;
            userscore++;
            compscore++;
        }
        if(usernumber==1 && number==2)
        {
            cout<<"Computer: Paper, Human: Rock, You Lose"<<endl;
            compscore++;
        }
        if(usernumber==1 && number==3)
        {
            cout<<"Computer: Scissors, Human: Rock, You Win"<<endl;
            userscore++;
        }
        if(usernumber==2 && number==1)
        {
            cout<<"Computer: Rock, Human Paper, You Win"<<endl;
            userscore++;
        }
        if(usernumber==2 && number==3)
        {
            cout<<"Computer: Scissors, Human: Paper, You Lose"<<endl;
            compscore++;
        }
        if(usernumber==3 && number==1)
        {
            cout<<"Computer: Rock, Human: Scissors, You Lose"<<endl;
            compscore++;
        }
        if(usernumber==3 && number==2)
        {
            cout<<"Computer: Paper, Human Scissors, You Win"<<endl;
            userscore++;
        }
        if(usernumber==4)
        {
            cout<<"Your Score: "<<userscore<<endl;
            cout<<"Computers Score: "<<compscore<<endl;
        }
    
    
    }


Last edited on
Please specify what exactly is going wrong. Being vague does not help us to find the issue you are having.
Please add one do while loop so that ur request from user will go as long as u are not pressing Q some thing like this

do
{
//code
} while(userpick!='Q')
Alright I put in the do while loop and it worked! But now I found another problem. It isn't adding up the final score correctly. It just ends up giving both scores 0.
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
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
    int number,usernumber = 0;
    char userpick;
    
    do{
    int userscore,compscore;
    userscore=0;
    compscore=0;
    
    
        
        srand(time(0));
        number = 1 + (rand() % 3) ;
        
        cout<<"Choose: [Rock, Paper, Scissors or Quit]: ";
        cin>>userpick;
        
        if(userpick=='r'|| userpick=='R')
        {
            usernumber=1;
        }
        if(userpick=='p'|| userpick=='P')
        {
            usernumber=2;
        }
        if(userpick=='s'|| userpick=='S')
        {
            usernumber=3;
        }
        if(userpick=='q'|| userpick=='Q')
        {
            usernumber=4;
        }
    
    
        if(usernumber==number)
        {
            cout<<"Computers: " <<userpick<< ", Human: "<<userpick<< ", Tie" << endl;
            userscore++;
            compscore++;
        }
        if(usernumber==1 && number==2)
        {
            cout<<"Computer: Paper, Human: Rock, You Lose"<<endl;
            compscore++;
        }
        if(usernumber==1 && number==3)
        {
            cout<<"Computer: Scissors, Human: Rock, You Win"<<endl;
            userscore++;
        }
        if(usernumber==2 && number==1)
        {
            cout<<"Computer: Rock, Human Paper, You Win"<<endl;
            userscore++;
        }
        if(usernumber==2 && number==3)
        {
            cout<<"Computer: Scissors, Human: Paper, You Lose"<<endl;
            compscore++;
        }
        if(usernumber==3 && number==1)
        {
            cout<<"Computer: Rock, Human: Scissors, You Lose"<<endl;
            compscore++;
        }
        if(usernumber==3 && number==2)
        {
            cout<<"Computer: Paper, Human Scissors, You Win"<<endl;
            userscore++;
        }
        if(usernumber==4)
        {
            cout<<"Your Score: "<<userscore<<endl;
            cout<<"Computers Score: "<<compscore<<endl;
        }
    }while(userpick!=4);
    
    
    return 0;
    
    }
Last edited on
1
2
3
int userscore,compscore;
userscore=0;
compscore=0;
Move this code outside the loop. You also can simplify it:

 
int userscore = 0, compscore = 0;


Topic archived. No new replies allowed.