Question: I have a code that I can not finish and do not understand how to fix it. Here is what I have... //Stephanie Rickert //
I have a code that I can not finish and do not understand how to fix it.
Here is what I have...
//Stephanie Rickert
// CIS 247C W2 BlackJack
//July 19 2018
#include
#include
#include
#include
#include
using namespace std;
// prototypes
string showCards(vector
short sumCardValues(vector
void playHand(short &cash); // & means "addres 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 staring out with $" << cash << endl;
//pause
cout << " Press any key to continue...";
_getch();
// create the loop variable
short choice = 0;
// run the application loop
do
{
// show the menu and get player's choice
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:
playHand(cash);
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...";
_getch();
} while (choice != 3); // !means NOT
return 0;
}
/// Show the cards in the vector (resizable aray)
string showCards(vector
{
string output = "";
for each (Card c in cards)
{
output += c.toString() + " ";
}
return output;
}
/// Add up the total value of the cards
short sumCardValues(vector
{
short total = 0;
for each (Card c in 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 AAraylist is a seizable array
// in C++, the ArrayList is called a vector
vector
vector
short dealerCardsTotal = 0;
short playerCardsTotal = 0;
// get be amount
short bet = 0;
cout << " Enter bet amount: ";
cin >> bet;
// create two cards for the dealer and show the first one
int number;
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 (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.ignore(100, ' ')
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 each (Card c in playerCards)
{
if (c.getValue() == 11)
{
cout << " Your total is " << playerCardsTotal << endl;
c.flapAceToOne();
cout << "However, you have an Ace that was converted to '1' 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 Aces
if (playerCardsTotal <= 21)
break;
}
}
}
// show the cards and the total
cout << " Here are your cards: " << showCards(playerCards) << endl;
cout << "Your total is " << playerCardsTotal << endl;
// if busted, stop the loop
if (playerCardsTotal > 21)
answer = 'S';
}
} while (toupper(answer) != 'S');
// if player's cardTotal is more than 21, the player busted so take money away
if (playerCardsTotal > 21)
{
cout << " You busted!" << endl;
cash = cash - bet;
}
else
{
// player stands so the dealer hits until 17 or greater
do
{
if (dealerCardsTotal < 17)
{
Card c;
cout << " Dealer was dealt: " << c.toString() << endl;
dealerCards.push_back(c); // add the card to the dealer's hand
cout << " Dealer cards: " << showCards(dealerCards) << endl;
dealerCardsTotal = sumCardValues(dealerCards);
cout << "Dealer total: " << dealerCardsTotal << endl;
}
} while (dealerCardsTotal < 17);
// show the cards for the dealer and the player
cout << " Your cards: " << showCards(playerCards) << " (" << playerCardsTotal << ")" << endl;
cout << " Dealer cards: " << showCards(dealerCards) << "(" << dealerCardsTotal << ")" << endl;
// who wins?
if (dealerCardsTotal > 21)
{
cout << " Dealer Busted!" << endl;
cash = cash + bet;
}
else if (dealerCardsTotal > playerCardsTotal)
{
cout << " Dealer Wins." << endl;
cash = cash - bet;
}
else if (playerCardsTotal > dealerCardsTotal)
{
cout << " You win!" << endl;
cash = cash + bet;
}
else
{
cout << " Your pushed the dealer (tie)." << endl;
}
}
// show the current cash position
cout << " Your current cash balance: $" << cash << endl;
}
The errors that show after I build are
Severity Code Description Project File Line Suppression State
Error C1083 Cannot open include file: 'Card.h': No such file or directory ConsoleApplication44 \\acad.dvuadmin.net\sce\homedir\d40462006\documents\visual studio 2015\projects\consoleapplication44\consoleapplication44\source2.cpp 1
Severity Code Description Project File Line Suppression State
Error C1083 Cannot open include file: 'Cards.cpp': No such file or directory ConsoleApplication44 \\acad.dvuadmin.net\sce\homedir\d40462006\documents\visual studio 2015\projects\consoleapplication44\consoleapplication44\source.cpp 8
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
