Undeclared identifer

trying to figure out why I can't call my functions roulette,high low, 21,
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#include <iostream>
#include <cstdlib>
using namespace std;

int highLow(int bet1)
{
    int rando1 = rand() % (11 - 1) + 1;
    int rando2 = rand() % (11 - 1) + 1;
    int guess;
    
    cout << rando1 << endl;
    cout << "Will the next number be 1)higher or 2)lower?" << endl;
    cin >> guess;
    
    cout << rando2 << endl;
    
    if ((rando1 < rando2) && (guess == 1))
    {
        return bet1;
    }
    else if ((rando1 > rando2) && (guess == 2))
    {
        return bet1;
    }
    else
    {
        return -bet1;
    }
}

int roulette(int bet2)
{
    int colorNum;
    int ranNum;
    
    string color;
    
    cout << "Pick a color (red or black)" << endl;
    cin >> color;
    
    cout << "Pick a number between (1 and 13)" << endl;
    cin >> colorNum;
    
    int x = rand() % 2;
    if(x == 0) cout<<"red";
    else cout << "black";
    
    ranNum= rand() % (14 - 1) + 1;
    cout << " ";
    cout << ranNum << endl;
    
    if(color== "red" && x == 'red' && colorNum == ranNum)
    {
        return bet2*16;
    }
    else if(color== "black" && x == 'black' && colorNum == ranNum)
    {
        return bet2*16;
    }
    else if(colorNum == ranNum)
    {
        return bet2*4;
    }
    else if((color =="red" && x == 'black') || (color =="black" && x == 'red'))
    {
        return bet2;
    }
    else
    {
        return -bet2;
    }
}

int twentyOne(int bet3)
{
    int card1 = rand() % (11 - 1) + 1;
    int card2 = rand() % (11 - 1) + 1;
    int sum = 0;
    int dealersHand;
    string playAgain;
    
    string choice;
    
    cout << "Your cards are: " << card1 << " and " << card2 << endl;
    
    sum = card1 + card2;
    
    cout << "Your card sum is " << sum << endl;
    
    while (sum < 21)
    {
        cout << "Would you like to hit or stay?" << endl;
        cin >> choice;
        
        if(choice == "hit")
        {
            sum += rand() % (11 - 1) + 1;
            cout << sum << endl;
        }
        else if(choice == "stay")
        {
            cout << sum << endl;
            break;
        }
    }
    
    cout << "Your sum is " << sum << endl;
    
    if(sum > 21)
    {
        cout << "You lose" << endl;
    }
    
    cout << "Now it is the dealer's turn" << endl;
    
    dealersHand = rand() % (24 - 16) + 16;
    cout << "Dealers hand is " << dealersHand << endl;
    
    if(dealersHand >= 22 && sum <= 21)
    {
        return bet3*3;
    }
    else if(sum > dealersHand && sum <=21)
    {
        return bet3*3;
    }
    else if(sum == dealersHand)
    {
        return bet3;
    }
    else
    {
        return -bet3;
    }
 
}

int betAmount(int userBalance)
{
    int userBet;
    
    cout << "How much would you like to bet?" << endl;
    cin >> userBet;
    
    if(userBet>userBalance)
    {
        cout << "Insufficient balance" << endl;
        return 5;
    }
    else
    {
        return userBet;
    }
}

void mainMenu()
{
    cout << "1) Play High-Low" << endl;
    cout << "2) Play Roulette" << endl;
    cout << "3) Play 21"  << endl;
    cout << "4) Set betting amount" << endl;
    cout << "5) Leave Casino " << endl;
}

int main()
{
    srand(time(0));
    int userBalance=rand() % (201 - 100) + 100;
    
    while(1)
    {
        cout << "Your balance is " << userBalance << endl;
        mainMenu();
        
        cout << "What game would you like to play?" << endl;
        
        int choice;
        int userBet = 5;
        
        cin >> choice;
        
        if(choice == 1)
        {
            while(1)
            {
                int payout = highLow(bet1);
                userBalance += payout;
                
                cout<< "Would you like to continue playing(y/n)" << endl;
                char play;
                cin >> play;
                
                if(play == 'y')
                {
                    highLow(bet1);
                }
                if(play == 'n')
                {
                    break;
                }
                if(userBalance <= 0)
                {
                    cout<<"You are bankrupt"<<endl;
                    break;
                }
            }
        }
        if(choice == 2)
        {
            while(1)
            {
                int payout = roulette(bet2);
                userBalance += payout;
                
                cout<< "Would you like to continue playing(y/n)" << endl;
                char play;
                cin >> play;
                
                if(play == 'y')
                {
                    roulette(bet2);
                }
                if(play == 'n')
                {
                    break;
                }
                if(userBalance <= 0)
                {
                    cout<<"You are bankrupt"<<endl;
                    break;
                }
            }
        }
        if(choice == 3)
        {
            while(1)
            {
                int payout = twentyOne(bet3);
                userBalance += payout;
                
                cout<< "Would you like to continue playing(y/n)" << endl;
                char play;
                cin >> play;
                
                if(play == 'y')
                {
                    twentyOne(bet3);
                }
                if(play == 'n')
                {
                    break;
                }
                if(userBalance <= 0)
                {
                    cout<<"You are bankrupt"<<endl;
                    break;
                }
            }
        }
        if(choice == 4)
        {
            userBet = betAmount(userBalance);
        }
        if(choice == 5)
        {
            cout<< "Goodbye" << endl;
            return 0;
        }
}
Last edited on
There are no variables named bet1, bet2 and bet3 inside the main() function.
Perhaps you meant to pass userBet as argument int payout = highLow(userBet); ?

Also note that strings use double quotes. Things like 'red' will not do what you expect.
Last edited on
Topic archived. No new replies allowed.