Question: I'm getting some errors in my C++ code. Please help. Here's my code: This is my source.cpp #include #include #include #include #include Card.h #include //

I'm getting some errors in my C++ code. Please help. Here's my code:

This is my source.cpp

#include

#include

#include

#include

#include "Card.h"

#include // Standard Template Library (STL)

using namespace std;

// prototypes

string showCards( vector cards );

short sumCardValues(vector cards);

void playHand(short &cash); // & means "address of" -- variable sent by reference"

/// Entry point to the application

int main()

{

// Set the starting cash and display it to the player

short cash = 100;

cout << "Welcome to BlackJack Extreme" << endl;

cout << " You are starting out with $" << cash << endl;

// pause

cout << " Press any key to coninue...";

_getch();

// create the loop variable

short choice = 0;

// run the application loop

do

{

// show the menu

system("cls"); // clear the console

cout << "Menu " << endl;

cout << "1) Play a hand" << endl;

cout << "2) Show current cash balance" << endl;

cout << "3) Exit" << endl;

cout << " Enter your choice: ";

cin >> choice;

// switch based on the choice

switch (choice)

{

case 1:

cout << " Playing a hand..." << endl;

break;

case 2:

cout << " Your current cash balance: $" << cash << endl;

break;

case 3:

cout << " Thank you for playing Extreme BlackJack!" << endl;

cout << " Your final cash position: $" << cash << endl;

break;

default:

cout << " Error. Please select from the menu." << endl;

break;

}

// pause

cout << " Press any key to continue..." << endl;

_getch();

}

while (choice != 3); // ! means NOT

return 0;

}

/// Show the cards in the vector (resizeable array)

string showCards(vector cards)

{

string output = "";

for (short i = 0; i < cards.size(); i++)

{

output += cards[i].toString() + " ";

}

return output;

}

/// Add up the total value of the cards

short sumCardValues(vector cards)

{

short total = 0;

for (Card cards)

{

total += c.getValue() //total = total + c.getValue();

}

return total;

}

/// Play a single hand of BlackJack

void playHand(short &cash)

{

// create two Arraylists that can hold Card objects

// an Arraylist is a resizeable array

// in C++, the Arraylist is called a vector

vector dealerCards;

vector playerCards;

short dealerCardsTotal = 0;

short playerCardsTotal = 0;

// get bet amount

short bet = 0;

cout << " Enter bet amount: ";

cin >> bet;

// create two cards for the dealer and show the first one

Card card1;

Card card2;

dealerCards.push_back(card1);

dealerCards.push_back(card2);

dealerCardsTotal = sumCardValues(dealerCards);

cout << " Dealer is showing: " << dealerCards[0].toString() << endl;

// create two cards for the player and show them both

playerCards.push_back(Card()); // create the card and put it directly into the Arraylist or (vector)

playerCards.push_back(Card());

playerCardsTotal = sumCardValues(playerCards);

cout << " Here are your cards: " << showCards(playerCards) << endl;

// give cards to the player until they stand ('S')

char answer = '?';

do

{

cout << " Do you want to hit or stand (H/S)? ";

cin.sync(); // flush the input stream (keyboard buffer)

cin >> answer;

cin.sync();

if (toupper(answer) == 'H')

{

// give a card to the player

Card c;

cout << " You were dealt this card: " << c.toString() << endl;

playerCards.push_back(c); // add card to player's hand

// sum up the card values

playerCardsTotal = sumCardValues(playerCards);

// did the player bust?

if (playerCardsTotal > 21)

{

// do you have an Ace that can be dropped to a 1 value?

for (Card c playerCards)

{

if (c.getValue() == 11)

{

cout << " Your total is: " << playerCardsTotal << endl;

c.flipAceToOne();

cout << "However, you have an Ace that was converted into one value" << endl;

playerCardsTotal = sumCardValues(playerCards);

cout << " Your new total is " << playerCardsTotal << endl;

// if we are good now, break out of the loop. Otherwise, keep looping and looking for the Aces

if (playerCardsTotal <= 21)

break;

}

}

}

}

}

while (toupper(answer) != 'S');

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!