BlackJack Program help

closed account (26X2y60M)
Two cards are dealt to each player. The dealer shows one card face up, and the other is face down. The player gets to see both of his or her cards and the total of them is added. Face cards (Kings, Queens, Jacks) are worth 10 points, Aces are worth 1 or 11 points, and all other cards are worth their face value. The goal of the game is to get as close to 21 (“blackjack”) without going over, which is called “busting.”

The human player goes first, making his or her decisions based on the single dealer card showing. The player has two choices: Hit or Stand. Hit means to take another card. Stand means that the player wishes no more cards, and ends the turn, allowing for the dealer to play.

The dealer must follow this algorithm: hit if their card total is less than 17 (or a soft 17), and must stand if it is 17 or higher.

Whichever player gets closest to 21 without exceeding it, wins.




Requirements

For this assignment you need to do the following:
Write a program that plays Blackjack

Have the program use at least 3 functions:
1. For the Dealer’s turn
2. For the Player’s turn
3. To deal a card

Have the program intelligently determine if an Ace should be interpreted as a 1 or an 11. This is somewhat difficult. You need to be able to also handle multiple aces. If there are any aces in the hand, and the total exceeds 21, change the 11 to a 1 (i.e. subtract 10) until there are no more aces in the hand or the total is below 21. (Hint: keep a counter that says how many aces have been dealt so far to each player.)

You don’t need to be able to deal from a real deck. Just generate a random number, where 1 is an ace and 10, 11, 12, and 13 represent the face cards. (To get the right distribution of cards.) You can ignore suit.

You must take into account the way that you display cards, as well as the actual value of the card. Face cards should output as J, Q, or K, respectively, but the value of each card is 10.

Grading

This is a difficult project that you should concentrate on correctness and readability. This code will be very difficult to follow without proper commenting. Please take time to make the user’s interface as readable and easy to understand as possible. I will grade for correctness, readability, comments, and a separate grade for appearance of output screen.
YOU MUST USE PASS BY REFERENCE PARAMETERS OR YOU WILL NOT RECEIVE FULL CREDIT





You may use the following code to generate a random integer:

// postcondition: returns a random integer from 1 to 13
int getRand()
{
if(i == 100) i = 0;
int rands[100];
srand((unsigned)time(0));

for(int index=0; index<100; index++)
{
rands[index] = (rand()%13)+1;
}

i++;

int n = rands[i];
return n;
}





To use this function, insert the following lines after your include directives:

static int i = -1;

int getRand();


and include the ctime library



Ideas for added functionality (bonus)

Deal from a deck of cards (correct number of each type of card). Reshuffle deck if it runs out.

Output cards in a nice way using the command prompt or make a GUI

Make a multi-player game option (still only one dealer)


These are just suggestions, feel free to be creative and come up with your own ideas!!




I dont want you to write out the whole program for me i just need some help

#include <iostream>
#include <ctime>
#include <string>
using namespace std;

void dealerTurn();
void playerTurn();
int dealCard();

static int i = -1;
int getRand();


int main()
{
int dealerNum, pCard1, pCard2;
string name;
char decision;

cout<<"Welcome to the Casino !!! "<<endl;
cout<<"Please enter your name : ";

cin>>name;
dealerNum = getRand();

cout<<"\n\nThe Dealers Cards \n? + "<<dealerNum<<endl;

pCard1 = getRand();
pCard2 = get Rand();

cout<<"\n\nYour Cards \n"<<pCard1<<" + "<<pCard2<<endl;

cout<<"Do you want to hit (h) or stand : ";
cin>>decision;

}

// postcondition: returns a random integer from 1 to 13
int getRand()
{
if(i == 100) i = 0;
int rands[100];
srand((unsigned)time(0));

for(int index=0; index<100; index++)
{
rands[index] = (rand()%13)+1;
}

i++;

int n = rands[i];
return n;

}


just need some help on how i would turn an 11 into a jack
Topic archived. No new replies allowed.