HOMEWORK 06 - NAÏVE BLACKJACK

Concepts

In this homework, we will combine everything we've learned so far with a focus on struct and string.

Overview

For this assignment, your job is to create a simple Blackjack game where a user plays against a computerized Dealer.

The Specifics

You must first create a struct named Card to represent a playing card. It should have two fields, a rank stored as an int and a suit stored as a string.

Next create a function that generates a random Card variable. Since this is Naïve Blackjack, we do not care if two cards are in play at once or how many of each card are available. This function should generate a random rank for the card (between 1-10) and a random suit for the card. The function should take nothing as input and return a Card as output.

At this point, everything is in place to start our game. Follow this pseudocode to complete the remainder of the assignment:

  1. While the Player wants to play:
    1. Deal a card to the Dealer, print the card, and display the Dealer's total
    2. Deal a card to the Player, print the card, and display the Player's total
    3. While the Player's total is less than or equal to 21:
      1. Deal a card to the Player, print the card, and display the Player's total
      2. If the Player's total is greater than 21, the Player busts. Go to Step #9
      3. Ask the Player if they want to "Hit" or "Stand". The user should type in "Hit" or "Stand" and you must store their response as a string.
      4. If they entered "Hit", return to step #5. If they entered "Stand" go on to Step #9
    4. If Player hasn't busted and while Dealer Total is less than 17:
      1. Deal a card to the Dealer, print the card, and display the Dealer's total
    5. Determine who wins the hand based on Player total and Dealer total
    6. Ask Player if they want to play again, "Yes" or "No". Again, the user should type in "Yes" or "No" and you must store their response as a string.
    7. If they entered "Yes", go back to Step #2. Otherwise quit the program.

It looks like a lot of steps, but the majority of those steps are describing the rules of Blackjack. Once completed, hopefully you find this assignment enjoyable to play and try to beat the computer. Sample output and program flow could be as follows:

Dealer shows the 3 of Clubs
Dealer total is: 3
You were dealt the 3 of Clubs
You were dealt the 7 of Hearts
Your total is: 10
Do you want to "Hit", "Stand"?
> Hit
You were dealt the 3 of Diamonds
Your total is: 13
Do you want to "Hit", "Stand"?
> Hit
You were dealt the 6 of Spades
Your total is: 19
Do you want to "Hit", "Stand"?
> Stand
Dealer was dealt the 6 of Diamonds
Dealer total is: 9
Dealer was dealt the 6 of Hearts
Dealer total is: 15
Dealer was dealt the 7 of Spades
Dealer total is: 22
Dealer busted!  You win
Do you want to play again?  "Yes" or "No"?
> No

We will revisit this assignment later to make a smarter Blackjack game where our cards are correctly limited to a standard 52 card deck.

Hints

Submission

You need to submit your solution of this homework (HW06) with two lab assignments: Lab06A and Lab06B. Detailed generic instructions for submitting homework assignments are available. For homework due this Wednesday, follow these specific steps: