Rock paper scissors game using functions??

So I'm working on this rock paper scissors game, and can't seem to get it to function properly! Where are my errors? I've tried several different things and can't get it right!

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
#include <iostream>
#include <string>

using namespace std;

int userchoice, compchoice, wincode;
string winner, convertchoice, convertwin;

int getUserChoice();
int getComputerChoice();
string determineWinner();
string displayResults(int compchoice, int userchoice, int wincode);

int main()
{   
    

    getUserChoice();
    if (userchoice == 1 || userchoice == 2 || userchoice == 3)
    {   
        getComputerChoice();
        determineWinner();
        displayResults(compchoice, userchoice, wincode);
    }
}
int getUserChoice(int userchoice)
{
    cout << "Game Menu" << endl;
    cout << "---------" << endl;
    cout << "1) Rock    " << endl;
    cout << "2) Paper   " << endl;
    cout << "3) Scissors" << endl;
    cout << "4) Quit    " << endl;
    cout << " " << endl;
    cout << "Enter your choice:";
    cin >> userchoice;

    getUserChoice();

    return 0;
}
int getComputerChoice()
{
    rand() % 3 + 1;

    return 0;
}
string determineWinner(int compchoice, int userchoice, string winner)
{
if (compchoice == 1)
{   
    if (userchoice == 1)
    {
        winner = "It's a tie!";
        wincode = 0;
    }
    else if (userchoice == 2)
    {
        winner = "User";
        wincode = 1;
    }
    else 
    {
        winner = "Computer";
        wincode = 2;
    }
}
else if (compchoice == 2)
{
    if (userchoice == 1)
    {
        winner = "Computer";
        wincode = 2;
    }
    else if (userchoice == 2)
    {
        winner = "It's a tie!";
        wincode = 0;
    }
    else 
    {
        winner = "User";
        wincode = 1;
    }

}
else 
{
    if (userchoice == 1)
    {
        winner = "User";
        wincode = 1;
    }
    else if (userchoice == 2)
    {
        winner = "Computer";
        wincode = 2;
    }
    else 
    {
        winner = "It's a tie!";
        wincode = 0;
    }
}
}
string displayResults(int userchoice, int compchoice, int wincode)
{
    cout << "============================================" << endl;
    convertchoice(userchoice);
    cout << "You selected: " << userchoice << endl;
    convertchoice(userchoice);
    cout << "The computer selected: " << compchoice << endl;
    convertwin(wincode);
    cout << "Game Winner: " << winner << endl;
    cout << "============================================" << endl;
}
string convertchoice(int compchoice, int userchoice)
{
    if (compchoice == 1 || userchoice == 1)
        return "Rock";
    else if (compchoice == 2 || userchoice == 2)
        return "Paper";
    else 
        return "Scissors";
}
string convertwin(int wincode)
{
    if (wincode == 1)
        winner = "User";
    else if (wincode == 2)
        winner = "Computer";
    else (wincode == 0)
        winner = "Tie";
}
system ("pause");
return 0;
Lot's of things are wrong here, and I'm not even looking at program flow:

1.) Your function prototypes don't match their definitions.

2.) You have two strings named "convertchoice" and "convertwin" in global scope, and it looks like you thought those would be function prototypes(?)

3.) In int getComputerChoice(), you're not doing anything. Line 44 does absolutely nothing except waste everybodys time, and then you return zero for no reason.

4.) main() doesn't return anything, although that's probably been magic'd in for you by your compiler.

5.) convertwin, convertchoice, displayResults and determineWinner don't return strings, even though you said they would.

6.) You're not passing parameters by reference, which means that any assignments you make to them do nothing.

7.) Lines 135 and 136 are not inside a function body.
Topic archived. No new replies allowed.