Blackjack 40

I'm creating a blackjack 40 game for my class. The code should output "BLACKJACK!" only once at the start if the player hits 40. The player will win 20$ once they hit blackjack. How would i change this code to make it only for the first hand.


if (total == 40) {
cout << "BLACKJACK 40!" << endl;
cout << "Player wins 20 dollars" << endl;
money += 20;
}

Do you have a variable counting how many hands have been played?

> How would i change this code to make it only for the first hand.
if (total == 40 && playedHands == 1)
No i haven't created a variable for playedHands. How would i creat one that would work efficiently for the whole game?
Last edited on
Well if your main is something really simple like
1
2
3
4
5
6
7
8
9
int main ( ) {
  char again;
  do {
    Blackjack game;
    game.play();
    cout << "Do you want to play again?";
    cin >> again;
  } while ( again == 'y' );
}


Then this seems easy enough.
1
2
3
4
5
6
7
8
9
10
11
int main ( ) {
  char again;
  int playedHands = 0;
  do {
    playedHands++;
    Blackjack game(playedHands);
    game.play();
    cout << "Do you want to play again?";
    cin >> again;
  } while ( again == 'y' );
}


But if you have a sprawling mass of spaghetti code, then maybe your first task is to clean up what you have before you start adding more features to it.

Topic archived. No new replies allowed.