Blackjack C++

Hello, I am making a blackjack simulation game in C++. I am currently working on the part of the program that lets a player split his card.

Before playing a hand, a player may split a pair, if his two cards are of equal rank (such as both are Eights). The two cards are split into two separate hands, each of which receives a second card.

However, when I try to split a pair, my program crashes because card 1 and card 2 are not initialized. How can I fix this?

Also, when the player splits the pair, he must risk a matching bet on the newly created hand (so if he had originally wagered $20 on one hand, now he is betting $20 on each of the two hands. How can I implement this into my program?

Here is my code:
http://pastebin.com/985rq03K
As for the immediate reason for crash: Lines 198-204:
1
2
3
4
5
6
7
if (split == 0){
    cout << "You are dealt a card face up and one face down." << endl;
    cout << "You:" << setw(29) << " " << endl;
    cout << "Face Down: ";
    card1 = dealCard(deck, total, shh, aces, width, size);
    cout << setw(9 - width) << "*" << endl;
}

are not executed if there is a split. This is when card1 is initialized. You should either put the hightlighted line outside of the if (split == 0) or inside if (split == 1){ provide alternative way of determining the card1 value.

But I think (I am not sure) that you should not call playBlackjack if there is a pair - what if the next two cards will be the same rank, and you end up with two pairs? The recursive call to this function is breaking the flow of your program turning it into meandering spaghetti. You should have alternative function that can handle this situation.
Last edited on
Topic archived. No new replies allowed.