Blackjack Program errors

Hello everyone!!

I am currently working on a blackjack program and I have a couple of errors that I do not know how to fix. I have checked online but unfortunately that did not help. I will comment out the places where the errors are at in the code. Uncomment to see the error. If anyone has any idea on how I could possibly fix these errors that would be great! Thanks for any future help!! Here is part one of my code...EDIT: I have no errors now, however look at the last post that I made.

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
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

const int NUMCARDS=52;
const int STRLEN=25;


void showRules(int &Option2, int reshuffle, int playersAces, int dealersAces, int naturalTest, int choice1);
void shuffle1();
void shuffle2();
void getInitialCards(int reshuffle, int &playersAces, int &dealersAces, int &naturalTest, int choice1);
void displayCardsandTotals(int pTotal, int dTotal);
void hitORStay(int &choice1);
void bigProcess(int &naturalTest, int &pTotal, int &dTotal, int &playersAces, int &dealersAces, int reshuffle, int choice1);
void NewHand(int &naturalTest, int &playersAces, int &dealersAces, int pWins, int pLosses, int pTies);
void checkOption(int &Option1);

int cards[NUMCARDS];
char cardNames1[NUMCARDS];
char cardNames2[NUMCARDS][STRLEN] = { "Ace of Spades", "Two of Spades", "Three of Spades", "Four of Spades",
		"Five of Spades", "Six of Spades", "Seven of Spades", "Eight of Spades", "Nine of Spades", 
		"Ten of Spades", "Jack of Spades", "Queen of Spades", "King of Spades", "Ace of Diamonds", 
		"Two of Diamonds", "Three of Diamonds", "Four of Diamonds", "Five of Diamonds", "Six of Diamonds", 
		"Seven of Diamonds", "Eight of Diamonds", "Nine of Diamonds", "Ten of Diamonds", "Jack of Diamonds",
		"Queen of Diamonds", "King of Diamonds", "Ace of Clubs", "Two of Clubs", "Three of Clubs", 
		"Four of Clubs", "Five of Clubs", "Six of Clubs", "Seven of Clubs", "Eight of Clubs", "Nine of Clubs",
		"Ten of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs", "Ace of Hearts", "Two of Hearts",
		"Three of Hearts", "Four of Hearts", "Five of Hearts", "Six of Hearts", "Seven of Hearts", "Eight of Hearts",
		"Nine of Hearts", "Ten of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts"};


int main()
{
	int Option1;
	int Option2=0;
	int playersAces=0;
	int dealersAces=0;
	int reshuffle;
	char choice1=0;
	int naturalTest=0;

		
	shuffle2();

	cout << "Please press 1 to view the rules for Blackjack.\n";
	cout << "Please press 2 to skip the rules and just play!\n";
	cin >> Option1;

	checkOption(Option1);

	if(Option1==1) {
		cout << endl;
		showRules(Option2, reshuffle, playersAces, dealersAces, naturalTest, choice1);
	}

	else {
		shuffle1();
		getInitialCards(reshuffle, playersAces, dealersAces, naturalTest, choice1);
	}
		


}

void checkOption(int &Option1)
{
	while((Option1!=1 && Option1!=2)) {
		cout << "I am sorry, but you have entered a wrong option!\n";
		cout << "Please press 1 to view the rules for Blackjack.\n";
		cout << "Please press 2 to skip the rules and just play!\n";
		cin >> Option1;
	}
}

void showRules(int &Option2, int reshuffle, int playersAces, int dealersAces, int naturalTest, int choice1)
{
	cout << "The rules of Blackjack are as follows:\n";
	cout << "The game is played with a standard 52 card deck!\n";
	cout << "The deck reshuffles after all 52 cards have been dealt!\n";
	cout << "If a player is dealt a natural 21 then they automatically win!\n";
	cout << "If both the player and the dealer's hands are equal, then the hand results in a push!\n";
	cout << "Wins, Losses, and Ties will be counted and given to the player at the end of the game!\n";
	cout << "Aces can count as either 11 or 1, and the J, Q, and K count as 10!\n";
	cout << "Now, please press 1 to begin playing Blackjack!\n";
	cin >> Option2;

	while((Option2!=1)) {
		cout << endl;
		cout << "I am sorry but you did not press 1!\n";
		cout << "Please press 1 to begin playing Blackjack!\n";
		cin >> Option2;
	}

	shuffle1();
	getInitialCards(reshuffle, playersAces, dealersAces, naturalTest, choice1);
}

void getInitialCards(int reshuffle, int &playersAces, int &dealersAces, int &naturalTest, int choice1)
{
	int pCard1, pCard2;
	int dCard1, dCard2;

	int pTotal, dTotal;
	int pTest = naturalTest;

	if(reshuffle==52) {
		cout << "Since all cards have been dealt, the deck has been reshuffled!\n";
		shuffle1();
		reshuffle=0;
	}
	reshuffle++;

	if(reshuffle==52) {
		cout << "Since all cards have been dealt, the deck has been reshuffled!\n";
		shuffle1();
		reshuffle=1;
	}
	
	pCard1 = cards[reshuffle];
	strcpy(cardNames1[1], cardNames2[reshuffle]); 
	reshuffle++;

	if(reshuffle==52) {
		cout << "Since all cards have been dealt, the deck has been reshuffled!\n";
		shuffle1();
		reshuffle=1;
	}

	pCard2 = cards[reshuffle];
	strcpy(cardNames1[2], cardNames2[reshuffle]); 
	reshuffle++;

	pTotal = pCard1 + pCard2;

	if(reshuffle==52) {
		cout << "Since all cards have been dealt, the deck has been reshuffled!\n";
		shuffle1();
		reshuffle=1;
	}

	dCard1 = cards[reshuffle];
	strcpy(cardNames1[3], cardNames2[reshuffle]);
	reshuffle++;

	if(reshuffle==52) {
		cout << "Since all cards have been dealt, the deck has been reshuffled!\n";
		shuffle1();
		reshuffle=1;
	}

	dCard2 = cards[reshuffle];
	strcpy(cardNames1[4], cardNames2[reshuffle]); 
	reshuffle++;

	dTotal = dCard1 + dCard2;

	if(pCard1 == 1) {
		playersAces = 1;
		pCard1+=10;
		pTotal = pCard1 + pCard2;
	}

	if(pCard2 == 1) {

		if (pCard1 !=11) {
			playersAces = 1;
			pCard2+=10;
			pTotal = pCard1 + pCard2;
		}

		else if (pCard1 = 11) {
			pCard2 = 1;
			pTotal = pCard1 + pCard2;
		}
	}

	if(dCard1 == 1) {
		dealersAces = 1;
		dCard1+=10;
		dTotal = dCard1 + dCard2;
	}

	if(dCard2 == 1) {

		if (dCard1 !=11) {
			dealersAces = 1;
			dCard2+=10;
			dTotal = dCard1 + dCard2;
		}

		else if (dCard1 = 11) {
			dCard2 = 1;
			dTotal = dCard1 + dCard2;
		}
}

	displayCardsandTotals(pTotal, dTotal);
	bigProcess(naturalTest, pTotal, dTotal, playersAces, dealersAces, reshuffle, choice1);
}
Last edited on
Here is the second part of my code...EDIT: I fixed all of the errors in this code..please look at the last post I made.

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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
void displayCardsandTotals(int pTotal, int dTotal)
{
	cout << "You are dealt a: " << cardNames1[1] << cardNames1[2] << "totalling, " << pTotal << endl;
	cout << "The dealer was dealt a: " << cardNames1[3] << cardNames1[4] << "totalling, " << dTotal << endl;

}

void hitORStay(int &choice1)
{
	cout << "Would you like to hit(press h) or stay(press s)?";
	cin >> choice1;
}

void bigProcess(int &naturalTest, int &pTotal, int &dTotal, int &playersAces, int &dealersAces, int reshuffle, int choice1)
{
	char choice2;
	int wins=0;
	int losses=0;
	int ties=0;

	int pWins = wins; 
	 int pLosses = losses; 
	 int pTies = ties; 
	 char pchoice2 = choice2; 

	if (naturalTest==0) {

		if ((pTotal==21) && (dTotal!=21)) {
			cout << "You were dealt blackjack!\n";
			cout << "Congratulations, you win!!\n";
			wins+=1;
			NewHand(naturalTest, playersAces, dealersAces, pWins, pLosses, pTies);
		}

		else if ((dTotal==21) && (pTotal==21)) {
			cout << "Both you and the dealer were dealt blackjack!\n";
			cout << "By rule, the Dealer wins and you lose!!\n";
			losses+=1;
			NewHand(naturalTest, playersAces, dealersAces, pWins, pLosses, pTies);
		}

		else if ((dTotal==21) && (pTotal!=21)) {
			cout << "The dealer was a blackjack!\n";
			cout << "Unfortunately, you lose!!\n";
			losses+=1;
			NewHand(naturalTest, playersAces, dealersAces, pWins, pLosses, pTies);
		}

		else  {
			naturalTest=1;
			hitORStay(choice1);
		}

	}

	if(((choice1== 'H') || (choice1=='h') && (naturalTest==1))) {
		reshuffle++;

		if((reshuffle=52)) {
			cout << "Since all cards in the deck have been dealt, the deck will be reshuffled!\n";
			shuffle1();
			reshuffle=1;
		}

		if((cards[reshuffle]==1)) {

			if(pTotal<=10) {
				playersAces=1;
				pTotal+=11;
			}

			else {
				pTotal+=1;
			}

		}

		else 
			pTotal+=cards[reshuffle];


		if((pTotal >= 22) && (playersAces==1)) {

			pTotal = pTotal - 10;
			playersAces=0;
		}

		if(pTotal>=22) {
			cout << "You are dealt a " << cardNames2[reshuffle] << " totalling, " << pTotal << endl;
			cout << "You have busted and the dealer wins!!\n";
			losses+=1;
			NewHand(naturalTest, playersAces, dealersAces, pWins, pLosses, pTies);
		}

		else if((pTotal==21)) {
			cout << "You are dealt a " << cardNames2[reshuffle] << " totalling, " << pTotal << endl;
			cout << "You have Blackjack, and you win!!!\n";
			wins+=1;
			NewHand(naturalTest, playersAces, dealersAces, pWins, pLosses, pTies);
		}

		else if((pTotal<=20)) {
			cout << "You are dealt a " << cardNames2[reshuffle] << " totalling, " << pTotal << endl;
			hitORStay(choice1);
			bigProcess(naturalTest, pTotal, dTotal, playersAces, dealersAces, reshuffle, choice1);
		}
	}
	
	else if (((choice2=='S') || (choice2=='s') && (naturalTest==1))) {
		
		while (dTotal <= 16) {
			reshuffle++;

			if(reshuffle==52) {
				cout << "Since all cards in the deck have been dealt, the deck has been reshuffled!\n";
				shuffle1();
				reshuffle=1;
			}

			if(cards[reshuffle]==1) {
				
				if(dTotal<=10) {
					dealersAces=1;
					dTotal+=11;
				}

				else {
					dTotal+=1;
				}
			}

			else 
				dTotal+= cards[reshuffle];


			if((dTotal>=22) && (dealersAces=1)) {
				dTotal= dTotal-10;
				dealersAces=0;
			}

			cout << "Dealer is dealt a " << cardNames2[reshuffle] << " totalling, " << dTotal << endl;

		}

		if(dTotal>=22) {
			cout << "The dealer has a total of " << dTotal << endl;
			cout << "Since the dealer busted, you win!!\n";
			wins+=1;
			NewHand(naturalTest, playersAces, dealersAces, pWins, pLosses, pTies);
		}

		else if(dTotal==21) {
			cout << "The dealer has blackjack!!\n";
			cout << "You lose!!\n";
			losses+=1;
			NewHand(naturalTest, playersAces, dealersAces, pWins, pLosses, pTies);
		}

		else if((dTotal>pTotal) && (dTotal<=20)) {
			cout << "The dealer stands with a " << dTotal << endl;
			cout << "The dealer wins!!\n";
			losses+=1;
			NewHand(naturalTest, playersAces, dealersAces, pWins, pLosses, pTies);
		}

		else if((dTotal==pTotal)) {
			cout << "The dealer stands with a " << dTotal << endl;
			cout << "Since you both have the same total, it is a push!!\n";
			ties+=1;
			NewHand(naturalTest, playersAces, dealersAces, pWins, pLosses, pTies);
		}

		else if ((dTotal < pTotal)) {
			cout << "Dealer stands with a " << dTotal << endl;
			cout << "You beat the dealers hand, you win!!\n";
			wins+=1;
			NewHand(naturalTest, playersAces, dealersAces, pWins, pLosses, pTies);
		}
	}

	else if ((choice2!='S') && (choice2!='s') && (choice2!='H') && (choice2!='h') && (naturalTest==1)) {
		cout << "You entered an invalid choice!!\n";
		hitORStay(choice1);
		bigProcess(naturalTest, pTotal, dTotal, playersAces, dealersAces, reshuffle, choice1);
	}
}

		

void NewHand(int &naturalTest, int &playersAces, int &dealersAces, int pWins, int pLosses, int pTies, int reshuffle)
{
	char choice2;
	cout << endl;
	cout << "Would you like to play another hand? (Press y or n)\n";
	cin >> choice2;

	while((choice2!='y') && (choice2!='Y') && (choice2!='n') && (choice2!='N')) {
		cout << "I am sorry but you have selected an invalid choice!\n";
		cout << "Please select either y or n!\n";
		cin >> choice2;
	}

	if((choice2=='Y') || (choice2=='y')) {
		cout << endl;
		naturalTest=0;
		playersAces=0;
		dealersAces=0;
		getInitialCards(reshuffle, playersAces, dealersAces, naturalTest, choice1);
	}

	else if((choice2=='N') || (choice2=='n')) {
		cout << endl;
		cout << "Thanks for playing Blackjack!\n";
		cout << "Your record was: " << pWins << "wins, " << pLosses << "losses, " << pTies << "ties.\n";
		cout << endl;
	}
}

void shuffle1()
{
	int m, temp, k;
	char temp2[STRLEN];

	srand((unsigned) time(NULL));

	m=52;
	while(m > 0) {
		
		k = rand() % m + 1;

		temp = cards[m];
		strcpy(temp2, cardNames2[m]);

		cards[m] = cards[k];
		strcpy(cardNames2[m], cardNames2[k]);

		cards[k] = temp;
		strcpy(cardNames2[k], temp2);

		k--;
	}
}

void shuffle2()
{
	int index, l;
	const int spadeVals=10;
	const int diamondVals=23;
	const int clubVals=36;
	const int heartVals=49;

	for(index=1; index<=spadeVals;index++) {
		cards[index] = index;
	}

	cards[11] = 10;
	cards[12] = 10;
	cards[13] = 10;

	l=1;

	for(index=14; index<=diamondVals; index++) {
		cards[index] = l;
		l++;
	}

	cards[24] = 10;
	cards[25] = 10;
	cards[26] = 10;

	l=1;
	
	for(index=27; index<=clubVals; index++) {
		cards[index] = l;
		l++;
	}

	cards[37] = 10;
	cards[38] = 10;
	cards[39] = 10;

	l=1;

	for(index=40; index<=heartVals; index++) {
		cards[index] = l;
		l++;
	}

	cards[50] = 10;
	cards[51] = 10;
	cards[52] = 10;

}
Last edited on
Ok so i fixed every error except for the "strcpy" errors. If anyone has any idea how I could fix these, your help would be greatly appreciated thanks.
Get rid of the extra parentheses around the two parameters.
Wow, yea that would be a good start lol, thanks for catching that..How about the strcpy errors in the first part of my code? I don't see what I am doing wrong there.
Ok so I have fixed every error in my program, however after running it, after the initial process of asking the user if he/she wants the rules displayed to them, nothing happens. I believe that it is a problem with my "getInitialCards" function however, I do not see what I am doing wrong. Could someone please take a look at it and provide feedback on possible ways to fix it?
Topic archived. No new replies allowed.