Pass the from function to main

I dont why the vuale does not return;

here is code
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
#include <iostream>
#include <string>
#include <ctime> // to use the time function
#include <cstdlib>

using namespace std;

int getUserChoose (int);
int getCompChose (int);
void WhoisWinner(int,int);

int main ()
{
    int comp,user;
    char answer;
    
    cout << "Welcome to the program of Rock, Paper, Scissors" << endl;
    cout << "The computer is ready to play the game" << endl;
    cout << "Are you ready to play the game" << endl;
    cout << "Y for yes and N for no " << endl;
    cin >> answer;
    
    while (answer == 'y' || answer == 'Y')
    {
        

        getUserChoose(user);
        getCompChose(comp);
        WhoisWinner(user,comp);

    }

}
int getUserChoose (int answer)
{
    
    char answerfromuser;
    int trannum;
    
    cout << "R = Rock; P = Paper; S = Scissors" << endl;
    cin >> answerfromuser;
    if (answerfromuser == 'R' || answerfromuser == 'r')
    {
        cout << "You have choose Rock " << endl;
        trannum = 1;
    }

    else if (answerfromuser == 'P' || answerfromuser == 'p')
    {
        cout << "You have choose Paper " << endl;
        trannum = 2;
        cout << trannum << endl;
    }

    else if (answerfromuser == 'S' || answerfromuser == 's')
    {
        cout << "You have choose Scissors " << endl;
        trannum = 3;
        
    }
    cout << trannum << "TN" << endl;

    return trannum;
}

int getCompChose (int num)
{
    srand( (unsigned int) time(NULL) );
    num = (1 + rand() % 3);
    cout << num << "RM" << endl;
    return num;
}
void WhoisWinner(int pervuser,int pervcomp)
{
    cout << pervuser << "U" << endl;
    cout << pervcomp << "C" << endl;
    /*
    if (pervuser == 1 && pervcomp == 1)
    {
        cout <<"Nice Try" << endl;
        cout <<"It a tie" << endl;
    
        if (pervcomp == 2)
        {
            cout << "Computer win" <<endl;
        }
        else
        {
            cout <<"You win!" << endl;
        }
    }
    else if (pervuser == 2)
    {
        if (pervcomp == 1)
        {
            cout <<"You win!" << endl;
            
        }
        else if (pervcomp == 2)
        {
            cout <<"Nice Try" << endl;
            cout <<"It a tie" << endl;
        }
        else
        {
            cout <<"Computer win!" << endl;
        }

    }
    else if (pervuser == 3)
    {
        if (pervcomp == 1)
        {
            cout <<"Computer win!" << endl;
            
        }
        else if (pervcomp == 2)
        {
            cout <<"You win! " << endl;
        }
        else
        {
            cout <<"Nice Try" << endl;
            cout <<"It a tie" << endl;
        }

    }
     */
    
}



here is the output


Welcome to the program of Rock, Paper, Scissors
The computer is ready to play the game
Are you ready to play the game
Y for yes and N for no 
Y
R = Rock; P = Paper; S = Scissors
R
You have choose Rock 
1TN
1RM
0U
0C
You're calling the functions, but you're not storing the value they return.

1
2
        getUserChoose(user);
        getCompChose(comp);


Did you mean to do something like this? I don't see that you need to send any parameters to these functions - you just want to get their choice and return that value to main?

1
2
        user = getUserChoose();
        comp = getCompChose();



Edit: You only need to call srand once - not every time you call the computer choice function.
Last edited on
I can dont do
1
2
user = getUserChoose();
        comp = getCompChose();
it say no match to function call to getUserChoose...
I got it work

Now i got problem at winner:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    cout << pervuser << "U" << endl;
    cout << pervcomp << "C" << endl;
    
    if (((pervcomp == 1) && (pervcomp = 1))||((pervuser == 2) && (pervcomp = 2))||((pervuser == 3) && (pervcomp = 3)))
    {
        cout << "It's a tie! " << endl;
    }
    
    else if (((pervuser == 1) && (pervcomp = 3))|| ((pervuser == 2) && (pervcomp = 1))|| ((pervuser == 3) && (pervcomp = 2)))
    {
        cout << "Congratulations! You win! " << endl;
    }
    
    else if (((pervuser == 1) && (pervcomp = 2))||((pervuser == 2) && (pervcomp = 3))|| ((pervuser == 3) && (pervcomp = 1)))
    {
        cout << "Oops! You lose! " << endl;
    }
    


here is an output

1
2
3
4
5
6
7
8
9
R = Rock; P = Paper; S = Scissors
p
You have choose Paper 
2
2TN
3RM
2U
3C
It's a tie!  


how can it be a tie?
Bump?
A few of your comparisons are using assignment (=) instead of comparison for equality (==).
Topic archived. No new replies allowed.