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

Can someone please help me get my code to execute!! Here is what I have: // Prog

ID: 3551957 • Letter: C

Question

Can someone please help me get my code to execute!!


Here is what I have:


// Programmer:


// Course:


// Assignment: Two-Dimensional Arrays


// Description: The program will use a 2D array and a random-number

// generation to play Blackjack and keep track of a playing-card deck.


// Input: User data entry and a playing-card deck represented as a two-

// dimensional array


// Output: A screen display showing the current card hands of each player

// and the dealer, their score, win and lose status, and a final representation

// of the card deck after the game is over


#include <iostream>

#include <iomanip>

#include <windows.h>

#include <string>


using namespace std;


//Prototypes

void initializeDeck(char cCardDeck[][13], int& round, int& dealer, bool p[], int& done);

int iNumberOfPlayers();

void deal(int players, char cCardDeck[4][13]);

void displayCards(int players, char cCardDeck[4][13]);

void scoreCards(char cCardDeck[4][13], int s[], int n, int& over);

bool draw(int i, int s);

void deal1(char CardDeck[][13],int n);

int iHighestCount(int s[],int num);

void final(int s,int n,int w ,char CardDeck[][13]);

int playAgain (int num);


void main (void)


{

bool bPlayerDraw[5]; //Boolean to determine if player holds (F)

//or draws card (T)

char cPlay = 'N'; //Character variable for play game input

char cCardDeck[4][13]; //Character array representing the card deck

int iSuit;

//0 = 2 card

//1 = 3 card

//2 = 4 card

//3 = 5 card

//4 = 6 card

//5 = 7 card

//6 = 8 card

//7 = 9 card

//8 = 10 card

//9 = jack card

//10 = queen card

//11 = king card

//12 = ace card

int iNumberOfDraws = 0; //Number of rounds of card draws


//0 = diamonds

//1 = hearts

//2 = clubs

//3 = spades


// ASCII character display reference for display card suit symbols

//3 = heart symbol

//4 = diamond symbol

//5 = club symbol

//6 = spade symbol


int iNumberOfPlayers = 0; //Number of players in current game

//iPlayer[0] is always the dealer

int i, k; //integer loop counters

srand(GetTickCount()); //Seed the random-number generator

int num, dealer, round, done, over21;

int score[5];

//main loop

num = iNumberOfPlayers();

while (iNumberOfPlayers >= 1)

{

initializeDeck(cCardDeck, round, dealer, bPlayerDraw, done);

deal(num, cCardDeck);

displayCards(num, cCardDeck);

scoreCards(cCardDeck, score, num, over21);

while(done < num && over21 < num + 1 && round < 5)

{

round++;

if(round <= dealer)

deal1(cCardDeck, 0);

for(i =1; i <= num; i++)

if (bPlayerDraw[i])

if(draw(i, score[i]))

deal1(cCardDeck,i);

else

{

bPlayerDraw[i] = false;

done++;

}

displayCards(num, cCardDeck);

scoreCards(cCardDeck,score, num, over21);

}

i = iHighestCount(score, num);

cout << " GAME OVER"<< endl;

for (k = 0; k <= num; k++)

final(score[k], k, i, cCardDeck);

num = playAgain(num);

}

system("pause");


}

void initializeDeck(char cCardDeck[][13], int& round, int& dealer, bool p[], int& done) //Initialize deck to "space"

{

{

round = 0;

done = 0;

dealer = rand() % 4;

//Initialize card array with "space"

for (int i = 0; i < 4; i++)

for (int j = 0; j < 13; j++)

cCardDeck[i][j] = ' ';

for(int k = 0; k < 4; k++)

p[k] = true;

}

}


int iNumberOfPlayers() //Prompt user for number of players

{

int num;

cout << "Welcome to Honest Sam's Blackjack Table."

<< " Glad to have you back!"

<< " Enter the number of players in the game."

<< " There must be at least 1 player but no more than four."

<< " Number of players:";

cin >> num;

while(num < 1 || num > 4) //Check to ensure correct user input

{

cout << "There must be at least one player but no more than four."

<< " Number of players:";

cin >> num;

}

return num;

}

void deal(int players, char cCardDeck[4][13]) //Deal 2 cards to each player

{

int i, j, k, l;


for (i = 0; i < players; i++)

for (j = 0; j < 2; j++)

{

do

{

k = rand () % 13;

l = rand () % 4;

}while(cCardDeck[l][k] != ' ');

cCardDeck[1][k] = i;

}

}

void displayCards(int players, char cCardDeck[4][13]) //Display dealer/player hands

{

int i, j ,k;

string card[] = {"2","3","4","5","6","7","8","9","10", "jack", "queen","king","ace"};

int iSuit[] = {3, 4, 5, 6};

bool d = false;

for (i = 0; i <= players; i++)

{

if (i == 0)

cout << "Dealers hand ";

else

cout << "Player" << i << "hand ";

for(j = 0; j < 4; j++)

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

if (cCardDeck[j][k] == i)

if ( !0 || d)

cout << (char) iSuit[j] << " " << card[k] << endl;

else

d = true;

}

}


void scoreCards(char cCardDeck[4][13], int s[], int n, int& over)

{

int i, j ,k;

over = 0;

for (i = 0; i <= n; i++)

{

s[i] = 0;

for (j = 0; j < 4; j++)

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

{

if (cCardDeck[j][k] == i)

{

if(k < 9)

s[i]+=(k+2);

else if(k < 12)

s[i]+= 10;

else

if(s[i]+11>21)

s[i]++;

else

s[i]+=11;

}

if (s[i]>21)

over++;

}

}

}

bool draw(int i, int s) //Prompt player to hold or draw

{

char h;

if(s>21)

return false;

cout << "Player" << i << "hold or draw?";

cin >> h;

if (toupper(h) == 'H')

return false;

return true;

}


void deal1(char CardDeck[][13],int n) //Deal random cards to each player

{

int k,l;

do

{

k=rand()%13;

l=rand()%4;

}while(CardDeck[l][k]!=' ');

CardDeck[l][k]=n;

}


int iHighestCount(int s[],int num) //Determine winner by score

{

int i,w;

for(i=0;i<=num;i++)

if(s[i]<=21)

{w=i;

i=num+3;

}

for(i=0;i<=num;i++)

if(s[i]>s[w]&&s[i]<=21)

w=i;

return w;

}

void final(int s,int n,int w ,char CardDeck[][13]) //Display all hands/display win or lose

{

int i,j,k;

string card[]={"2","3","4","5","6","7","8","9","10","jack","queen","king","ace"};

int iSuit[] = {4,3,5,6};

if(n==0)

cout<<"Dealers hand ";

else

cout<<"Player "<<n<<"s hand ";

for(j=0;j<4;j++)

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

if(CardDeck[j][k]==n)

cout<<(char)iSuit[j]<<" "<<card[k]<<", ";

cout<<s<<" ";

if(n==w)

cout<<"Win! ";

else

cout<<"Lose ";


}

int playAgain (int num) // Prompt each user to play again, yes or no

{

int a=0,i;

char again;

for(int i=1;i<=num;i++)

{

cout<<"player "<<i<<" play again(y/n)? ";

cin>>again;

if(toupper(again)=='Y')

a++;

}

return a;

}

Explanation / Answer

// Assignment: Two-Dimensional Arrays

// Description: The program will use a 2D array and a random-number

// generation to play Blackjack and keep track of a playing-card deck.

// Input: User data entry and a playing-card deck represented as a two-

// dimensional array

// Output: A screen display showing the current card hands of each player

// and the dealer, their score, win and lose status, and a final representation

// of the card deck after the game is over

#include <iostream>

#include <iomanip>

#include <windows.h>

using namespace std;

void deal(int ,bool [4][13],char [4][13],char [5][5][2]);

void printcards(int,char [5][5][2]);

void printdeck(bool[4][13],char[4][13]);

int main (void)

{

bool bPlayerDraw[5]; //Boolean to determine if player holds (F)

//or draws card (T)

char cPlay = 'N'; //Character variable for play game input

char cCardDeck[4][13]; //Character array representing the card deck

int iCard; //Card array index

//0 = 2 card

//1 = 3 card

//2 = 4 card

//3 = 5 card

//4 = 6 card

//5 = 7 card

//6 = 8 card

//7 = 9 card

//8 = 10 card

//9 = jack card

//10 = queen card

//11 = king card

//12 = ace card

int iNumberOfDraws = 0; //Number of rounds of card draws

int iSuit; //Suit array index

//0 = diamonds

//1 = hearts

//2 = clubs

//3 = spades

// ASCII character display reference for display card suit symbols

//3 = heart symbol

//4 = diamond symbol

//5 = club symbol

//6 = spade symbol

int iNumberOfPlayers = 0;//Number of players in current game

int iPlayerCount[5]; //Integer array to holder each player's count

//iPlayer[0] is always the dealer

int iHighestCount = 0; //Highest count for a single game

bool used[4][13];

char hand[5][5][2];

int k, m; //integer loop counters

srand(GetTickCount()); //Seed the random-number generator

//srand(5);

//Main game loop

//Enter your code here