Homework 7

Assigned 3/11/05

Task: Write a program that allows a user to play blackjack. In Blackjack, the dealer deals two cards to the player and then two cards to herself. The player gets to see both of their own cards and the second of the dealer's cards. After the cards are dealt, the player has the option of hitting (getting another card) or staying (getting no more cards). The player can hit either until they decide to stay or until they bust (have a total of more than 21).

Once the player is finished, the dealer will go through the same process, except that the dealer does not get to choose whether to hit or stay. The dealer will always hit when her hand totals 16 or less, and will always stay when her hand totals 17 or more.

If the player is dealt an Ace and a 10 or a face card in the initial deal, they get blackjack and they automatically win.

Aces can be worth 1 or 11. Faces cards are worth 10. All other cards are worth their face value.

Your program should allow the user to play as many times as they want. When the user is done, your program should tell them how many wins, losses, and ties they had.

EXTRA CREDIT: Write your own card dealing function. You can base it on the roll() function from the craps assignment. This dealing function must be submitted by Monday, March 14. It will be worth 4 homework points. On Monday, I'll post a dealing function for those of you that don't get one before then.

Purpose: To practice integrating all of the many skills you have learned thus far.


#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

// Put your function prototypes here
int deal();

int main()
{
        // Declare your variables here

        srand((unsigned)time(NULL));

        // Write your code here
}

/* This function returns a number from 1 to 13, representing the cards Ace
through King. */
int deal(void)
{
	return (rand()%13)+1;
}