Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to create blackjack with one deck and a player and dealer. I would like t

ID: 3636056 • Letter: I

Question

I need to create blackjack with one deck and a player and dealer. I would like to keep using this type of code. In this code, even after the player has chosen to hold, it gives them another 2 cards the next turn. Also it doesnt stop running when someone goes over 21 or gets 21. the program just keeps adding 2 cards each turn. I need it to just add one card instead of 2 for each turn, after the initial turn (since you are given 2 cards on the initial turn). any sort of help would be appreciated, thank you.

#include

#include

using namespace std;

enum hands {PLAYER_HAND = 0, DEALER_HAND};

void showResult (hands h, int theHand);

void whoWins (int playerHand, int houseHand);

int main()

{

int deck[4][13]; //Initialize Deck Array

int Player[11]; // initialize maximum amount of cards player can have

int playertotal = 0; //Total Value of Player's cards

int dealer[11];

int dealertotal = 0;

bool hit= true;

int face, suit;

hands hand;

for (suit=0;suit<4; suit++) //Setup Array for Deck

{

for (face=0; face<13; face++)

deck[suit][face] = face; //Gives each card a number

}

for (suit=0;suit<4; suit++) //Setup Array for Deck

{

for (face=0; face<13; face++)

{

int s = rand()%4;

int f = rand()%13;

int randomCard = deck[s][f];

int tmpCard = deck[suit][face];

deck[suit][face] = randomCard;

deck[s][f] = tmpCard;

}

}

char choise;

hand = PLAYER_HAND;

while(true)

{

do

{

if(hand == PLAYER_HAND)

cout << " Player: " << endl;

else

cout << " Dealer: " << endl;

for (int x=0; x<=1; x++) //DEAL 2 CARDS

{

suit = rand()%4;

face = rand()%13;

if (deck[suit][face] != -1)

{

Player[x] = deck[suit][face];

if(hand == PLAYER_HAND)

playertotal = playertotal + deck[suit][face];

else

dealertotal = dealertotal + deck[suit][face];

deck [suit][face] = -1; //card selected becomes a 0 in the array so it wont repeat

cout << "Card " << (x+1) << ": " << Player[x] << endl;

}

else { x=x-1;} //if card chosen is a zero, loop goes back to top

}

if(hand == PLAYER_HAND)

cout<<"Your current hand value is: "<< playertotal <
else

cout<<"Your current hand value is: "<< dealertotal <
if(hand == PLAYER_HAND)

{

showResult(hand, playertotal);

hand = DEALER_HAND;

}

else

{

showResult(hand, dealertotal);

hand = PLAYER_HAND;

}

cout << " Would you like to hit(h) or stay(s)?"<
cin >> choise;

}while(choise == 'h' || choise =='H');

}

whoWins(playertotal, dealertotal);

return 0;

}

void showResult (hands h, int theHand)

{

if (theHand > 21)

{

if (h == PLAYER_HAND)

cout << "Player Busted!" << endl;

else

cout << "House Busted!" << endl;

exit(0);

}

else

{

if (h == PLAYER_HAND)

cout << "Player Holds on "<< theHand << endl;

else

cout << "House Holds on " << theHand << endl;

}

}

void whoWins (int playerHand, int houseHand)

{

if (playerHand > houseHand)

cout << "Player Wins! " << endl;

else

cout << "House Wins! " << endl;

}

Explanation / Answer

#include #include #include #include using namespace std; enum hands {PLAYER_HAND = 0, DEALER_HAND}; void showResult (hands h, int theHand); void whoWins (int playerHand, int houseHand,bool stay_dealer,bool stay_player); int main() { int z=1; //number of cards dealt int deck[4][13]; //Initialize Deck Array int Player[11]; // initialize maximum amount of cards player can have int playertotal = 0; //Total Value of Player's cards int dealer[11]; int dealertotal = 0; bool hit= true; int face, suit=0; bool stay_dealer=false; bool stay_player=false; hands hand; for (suit=0;suit
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote