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

C++ program to simulate a game of Blackjack between two to four players. Your pr

ID: 3628116 • Letter: C

Question

C++ program to simulate a game of Blackjack between two to four players. Your program must incorporate a two-dimensional array to represent the suit and the value of each card dealt to a player, keep track of which cards have been dealt to which player, and use a random-number generator to pick each card to be dealt to a player.
// 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 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
int k, m; //integer loop counters
srand(GetTickCount()); //Seed the random-number generator
//Main game loop
//Enter your code here…

Explanation / Answer

please rate - thanks

sorry, I don't know the rules of blackjack for scoring

this should get you started

I didn't understand what some of the variables are for

// 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…
//initialize deck
for(k=0;k<4;k++)
     for(m=0;m<13;m++)
          {cCardDeck[k][m]=(char)(m);
           used[k][m]=false;
          }
cout<<"How many players in the game (2-4)? ";
cin>>iNumberOfPlayers;
while(iNumberOfPlayers<2||iNumberOfPlayers>4)
    {cout<<"invalid entry ";
    cout<<"How many players in the game (2-4)? ";
    cin>>iNumberOfPlayers;
    }
deal(iNumberOfPlayers,used,cCardDeck,hand);
printcards(iNumberOfPlayers,hand);
printdeck(used,cCardDeck);

system("pause");
return 0;
}
void deal(int players,bool used[4][13],char cCardDeck[4][13],
          char hand[5][5][2])
{int i,j,k,l;

for(i=0;i<=players;i++)
     for(j=0;j<5;j++)
          {do
             {k=rand()%13;
              l=rand()%4;
              }while(used[k][l]);
           hand[i][j][0]=k;
           hand[i][j][1]=l;
           used[l][k]=true;
             
          }
    
}
void printcards(int players,char hand[5][5][2])
{int i,j;
string card[]={"2","3","4","5","6","7","8","9","10","jack","queen","king","ace"};
int code[]={4,3,5,6};
for(i=0;i<=players;i++)
     {if(i==0)
          cout<<"Dealers hand ";
     else
         cout<<"Player "<<i<<"s hand ";
      for(j=0;j<5;j++)
         {//cout<<(int)hand[i][j][0]<<" "<<(int)hand[i][j][1]<<endl;
          cout<<card[(int)hand[i][j][0]]<<" "<<(char)code[ (int)hand[i][j][1]]<<endl;
          }
          }
}
void printdeck(bool used[4][13],char cCardDeck[4][13])
{int i,j;
string card[]={"2","3","4","5","6","7","8","9","10","jack","queen","king","ace"};
int code[]={4,3,5,6};
cout<<"Cards remaining in the deck ";
for(i=0;i<4;i++)
   for(j=0;j<13;j++)
        if(!used[i][j])
             cout<<(char)code[i]<<" "<<card [j]<<endl;

}


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