Program I been making

So I have been making this 21 game, not finished yet and I know I need to make some changes to the aces and what not, but for right now I am stuck on the rand() command. Say I draw a 4 and a 7, it will equal 11, but when I say yes to continuing I will get a 2 card, then I will say yes, and then get a 3 card, and a 4 card and so on and so on. The house does the same exact thing, but a lot more frequent so its really annoying. I was just wondering if this is just part of the command or if I can fix it so this never happens, unless its actually by random chance. Thanks for the help in advance!

P.S. If there is any newbie mistakes like a better way to program a line or something in general, just say so!



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
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <windows.h>

void Winner(int &Card1, int &Card2, int &cardTotal, int &bet, int &totalChips);
void cardGenerator(int &rNumber);
void keepGoing(int &cardTotal, int &bet, int &totalChips);
void twentyOne(int totalchips);
using namespace std;

int main()
{
cout << "Welcome to the Casino.\n";
cout << "You have recieved 100 chips.\n\n\n";
twentyOne(100);

}

void twentyOne(int totalchips)
{
int bet;


cout << "Please enter a bet: ";
cin >> bet;

srand(time(0));
int rNumber[4]= {1+(rand()%12), 1+(rand()%12), 1+(rand()%12), 1+(rand()%12)};
string answer;

    cout << "You have recieved a(n) ";
cardGenerator(rNumber[0]);
    cout << "and a(n) ";
cardGenerator(rNumber[1]);
int cardTotal = rNumber[0] + rNumber[1];

cout << "\n\nYour hand equals " << cardTotal << "\n\n";
cout << "The house has a(n) ";
cardGenerator(rNumber[2]);
cout << "and another face down card.";

cout << "\n\nThe house's hand equals " << rNumber[2] << endl << endl;

keepGoing(cardTotal, bet, totalchips);

Winner(rNumber[2], rNumber[3], cardTotal, bet, totalchips);

}



void keepGoing(int &cardTotal, int &bet, int &totalChips)

{

while (cardTotal < 22)
{

string answer;

for(int x = 0; x < 6; x++)
{
    cout << "Would you like to keep going?\n";
    cin >> answer;

        if (answer == "Yes" or answer == "yes")
        {
        srand(time(0));
        int rNumber[6]= {1+(rand()%12), 1+(rand()%12),  1+(rand()%12), 1+(rand()%12), 1+(rand()%12), 1+(rand()%12)};

            cout << "\n\nYou drew a ";
            cardGenerator(rNumber[x]);
            cout << "\n";
            Sleep(2000);
            cardTotal = cardTotal + rNumber[x];
            cout << endl << endl << "Your new total is " << cardTotal << endl << endl;
            Sleep(2000);
        }

break;
}
    if(answer == "No" or answer == "no")
        {
            break;
        }

}

    if (cardTotal > 21)
    {
        cout << "Bust!\n";
        totalChips = totalChips - bet;
        cout << "Total chips are now " << totalChips << "\n\n\n\n\n\n\n";
        Sleep(2000);
        twentyOne(totalChips);
    }


}

void cardGenerator(int &rNumber)
{


            if(rNumber == 1)
                    {
                    rNumber = 11;
                    cout << "Ace ";
                    }
           else if (rNumber < 10)
                    {
                    cout << rNumber << " ";
                    }

            else if(rNumber == 12 )
                    {
                    rNumber = 10;
                    cout << "King ";
                    }
            else if(rNumber == 11)
                    {
                    rNumber = 10;
                        cout << "Queen ";
                    }
            else if(rNumber == 10)
                    {
                        rNumber = 10;
                        cout <<"Jack ";
                    }
}


void Winner(int &Card1, int &Card2, int &cardTotal, int &bet, int &totalChips)
{
int rNumber;

cout << "\nThe dealer reveals his second card.\n\n" << "The dealer now has a(n) ";
rNumber = Card1;
cardGenerator(rNumber);
Card1 = rNumber;
cout << " and a(n) ";
rNumber = Card2;
cardGenerator(rNumber);
Card2 = rNumber;
cout << "\n";

int houseTotal = Card1 + Card2;
cout << "The dealer's hand now equals " << houseTotal << endl;
Sleep(5000);


while (houseTotal < 16 or houseTotal < cardTotal)
{
    for(int x = 0; x < 6; x++)
{
       srand(time(0));
       int rNumber[6]= {1+(rand()%12), 1+(rand()%12), 1+(rand()%12), 1+(rand()%12), 1+(rand()%12), 1+(rand()%12)};
       cout << "The dealer drew ";
       cardGenerator(rNumber[x]);
       cout << "\n";
       Sleep(1000);
       houseTotal = houseTotal + rNumber[x];
       cout << "The dealer's hand is now " << houseTotal << endl;
       Sleep(3000);
break;
}

}

if (houseTotal > 21)
{
    cout << "House busted, you win!\n";
    totalChips = totalChips + bet;
    cout << "Total chips are now " << totalChips << "\n\n\n\n\n\n\n";
    Sleep(5000);
}
else if(houseTotal < cardTotal)
{
    cout << "House lost, you win!\n";
    totalChips = totalChips + bet;
    cout << "Total chips are now " << totalChips << "\n\n\n\n\n\n\n";
}
else if (houseTotal == cardTotal or houseTotal > cardTotal )
{
    cout <<  "Sorry house won!\n";
    totalChips = totalChips - bet;
    cout << "Total chips are now " << totalChips << "\n\n\n\n\n\n\n";
    Sleep(5000);
}


twentyOne(totalChips);
}
Last edited on
This code dosn't compile for me

this while (houseTotal < 16 or houseTotal < cardTotal) is not a valid c++ statement. or should be ||
Last edited on
or is a C++ keyword.
Still need help ;(. Haven't figured it out yet.
Topic archived. No new replies allowed.