I'm trying to code blackjack and I'm done, but I have this one issue. For the dealer taking more cards it's supposed to keep taking more cards until the "dealerTotal" is 17 or higher. But, I have the problem that the dealer will always only take one card and then stand. This code worked before and would keep taking another card until it was over 16. But, now it doesn't work, and I've used some version diff checking and nothing is different.
if (playerTotal <= 21)
{
cout << endl;
cout << "The dealer's two cards are: " << dealercard1 << " & " << dealercard2 << endl;
cout << "The dealer's total is: " << dealerTotal << endl;
while (loop == 1) // will keep looping until it breaks (over 17)
{
if (dealerTotal < 17)
{
dealercardNew = rand() % 13 + 1;
cout << endl;
cout << "The dealer's new card is: " << dealercardNew << endl;
if (dealercardNew > 10) // sets jack, queen and king to 10
{
dealercardNew = 10;
}
dealerTotal = dealerTotal + dealercardNew; // adding new card to total
cout << "The dealer's new total is: " << dealerTotal << endl;
if (dealerTotal > 21) // dealer loss
{
cout << "The dealer's deck went Bust!" << endl;
break;
}
if (dealerTotal > 17 || dealerTotal == 17)
{
cout << "The Dealer chose to stand with: " << dealerTotal << endl;
break;
}
}
else (dealerTotal > 17 || dealerTotal == 17)
cout << "The Dealer chose to stand with: " << dealerTotal << endl;
break;
}
}
I have Tried removing the last else and turning it into an else if but both do not work.
Removing the else entirely makes it not do anything after the total is read out
Adding else if didnt do anything that i could notice.
The two initial cards are created using this code if helpful:
srand(time(NULL));
Pcard1 = rand() % 13 + 1;
Pcard2 = rand() % 13 + 1;
dealercard1 = rand() % 13 + 1;
dealercard2 = rand() % 13 + 1;
Aucun commentaire:
Enregistrer un commentaire