Classwork 6: Blackjack Strategy

Objectives

To practice using if statements.

The Assignment

For this assignment, you will write a program that tells the user to 'hit' or 'stand' in a game of Blackjack (also known as Twenty-one).

Blackjack is a casino card game where the objective is to have the cards you are dealt total up as close to 21 as possible. If you go over 21 (a bust), you lose. The cards are from a standard deck (most casinos use several decks at once). Cards 2-10 have the values shown. Face cards (Jack, Queen and King) have value 10. An Ace is either 1 or 11, whichever is to your advantage.

Each player is initially dealt two cards face up. The dealer is given 1 card face up and 1 card face down. Then, each player gets one turn to ask for as many extra cards as he wants, one at a time. To receive another card, the player "hits". When he doesn't want any more cards, he "stands".

If you don't know Blackjack, you can find the rules for Blackjack on Wikipedia, but it is simplest to wait for the demo in class.

The strategy that you will implement is a rather simple one. You will probably lose money slowly in a casino if you follow this strategy. (If you don't follow a strategy like this one, you will lose money quickly.)

The sample runs of your program should look like this:


PT[122]% gcc -Wall blackjack.c

PT[123]% ./a.out
Here's some advice for blackjack.
Tell me which card the dealer is showing.
Enter 2-9, 10 (Jack, Queen, King) or 11 (Ace): 7
What is the combined total of your hand? 12
You should: Hit

PT[124]% ./a.out
Here's some advice for blackjack.
Tell me which card the dealer is showing.
Enter 2-9, 10 (Jack, Queen, King) or 11 (Ace): 5
What is the combined total of your hand? 12
You should: Stand

PT[125]% ./a.out
Here's some advice for blackjack.
Tell me which card the dealer is showing.
Enter 2-9, 10 (Jack, Queen, King) or 11 (Ace): 11
What is the combined total of your hand? 19
You should: Stand

PT[126]% 

Notes

What to submit

Use the script command to record yourself compiling and running your program several times with different hit/stand results. (Do not record yourself editing your program!) Exit from script. Submit your program and the typescript file:

submit cs104_chang cw06 blackjack.c typescript