Your objective is to beat the dealer's hand (see below)
without going over 21.
Cards dealt (randomly) are between 1 and 11.
You first receive 2 cards, and then are asked
(in a loop) whether you want another card.
You can request as many cards as you like,
one at a time, but don't go over 21.
Copyright © 2024 1QUIZZ.COM - All rights reserved.
Answers & Comments
In general you can do this in two ways:
a)
while (neither player has stopped taking cards or is bust) {
...
}
b)
while (true) {
...
if (both players have stopped or are bust) break;
...
}
In both cases you need appropriate conditions in the place of that pseudo code.
Each player needs a variable for current points and one for "is_still_drawing_new_cards".
Inside the loop, first the dealer, then the player make a decision between "hit" or "stay" (assuming they are still drawing and not bust, so each player's code has to be wrapped in an appropriate if block).
A common blackjack rule of thumb is to hit as long as you have 14 or less.