I have no idea how to even begin. Please help Enter the following source, which
ID: 3535864 • Letter: I
Question
I have no idea how to even begin. Please help
Enter the following source, which will set up the 2D array and the recommended variable declarations. It is up to the student to design and implement the remainder of the program code.
// Programmer: (put your name here)
// Course: COMP220
// 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;
{
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…
Here is a sample of the finished program’s output.
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 one player but no more than four.
Number of players: 3
Dealer Player 1 Player 2 Player 3
Card 1: 5♣ 7♠4♥ Q♥
Card 2: 5â™ K♥ 5♥ 2â™
Card 3: J♥ 4♠6♣ 10♥
Card 4: Hold Hold Q♣ Hold
Card 5: Hold Hold Hold Hold
Final: 20 21 25 22
Lose Win! Lose Lose
Display entire card deck, rows = suits, columns = card
0 = dealer card, 1 = Player 1 card, 2 = Player 2 card, etc.
Welcome to Honest Sam's Blackjack Table
Do you feel lucky today?
Do you think you should take what you have left and go home?
Press Y or y to play or any other key to exit the game.
2 3 4 5 6 7 8 9 10 J Q K A ♥
2 2
3 0 3 1
♦
♣
0 2
2
â™ 3
1 0
1
Explanation / Answer
#include <stdio.h> #include <time.h> #include <string.h> //Define All Global Variables Here int MinNumber,MaxNumber,Hand,Dealer,Turn; char action[20]; char *HitIt = "h"; char *Stay = "s"; char *DealIt = "d"; char *Quit = "q"; //Define All Functions Here int getrand(int min, int max); int srand(unsigned); int rand(); void Hit(); void Deal(); void PlayerHit(); void DealerHit(); void Determine(); int main(int argc, const char * argv[]) { MaxNumber = 11; MinNumber = 0; Hand = 0; Dealer = 0; Turn = 1; srand(time(NULL)); Deal(); Determine(); return 0; } // Gets two random numbers from 1 to 13 and adds them together and sets the Hand variable to it // Gets two random numbers from 1 to 13 and adds them together and sets the Dealer variable to it void Deal() { Hand = getrand(MinNumber,MaxNumber)+getrand(MinNumber,Max Number); Dealer = getrand(MinNumber,MaxNumber)+getrand(MinNumber,Max Number); Turn = 1; if(Dealer > 20 || Hand > 20) { printf(" Sorry but there was an error :( "); printf(" Player"); printf(" Dealer "); printf(" %i ",Hand); printf(" %i ",Dealer); } } // Adds a random number from 1-13 to the players hand variable void PlayerHit() { if(Turn == 1) { Hand += getrand(MinNumber, MaxNumber); } else { printf("Sorry But there was an error"); } } // Adds a random number from 1-13 to the dealers Dealer variable void DealerHit() { if(Turn == 0) { Dealer += getrand(MinNumber, MaxNumber); } else { printf("Sorry But there was a dealer error"); } } void Determine() { if(action != NULL) { if(strcmp(action,HitIt) == 0) { Turn = 1; PlayerHit(); } if(strcmp(action,Stay) == 0) { if(Dealer < 17) { Turn = 0; DealerHit(); } } if(strcmp(action,DealIt) == 0) { printf(" New Hand "); Deal(); } } if(Turn == 0) { if(Dealer < 17) { DealerHit(); Determine(); } else if((Dealer < Hand) && (Hand <= 21)) { DealerHit(); Determine(); } } // Start Determining who wins if(Hand == 21 && Dealer != 21) { printf("Player: %i Black Jack!! you Win ",Hand); printf("Dealer: %i",Dealer); printf(" Deal(d): "); scanf("%s",action); Determine(); } else if(Dealer == 21) { printf("Player: %i ",Hand); printf("Dealer: %i Black Jack!! Dealer Wins",Dealer); printf(" Deal(d): "); scanf("%s",action); Determine(); } else if(Hand > 21 && Dealer < 21) { printf("Player: %i you busted!! ",Hand); printf("Dealer: %i Dealer Wins",Dealer); printf(" Deal(d): "); scanf("%s",action); Determine(); } else if(Hand < 21 && Dealer > 21) { printf("Player: %i you Win ",Hand); printf("Dealer: %i Dealer busted!!",Dealer); printf(" Deal(d): "); scanf("%s",action); Determine(); } else if(Hand > 21 && Dealer > 21) { printf("Player: %i you Busted!! ",Hand); printf("Dealer: %i dealer busted!!",Dealer); printf(" Deal(d): "); scanf("%s",action); Determine(); } else { if(Turn == 1) { if(Dealer > Hand) { printf("Player: %i ",Hand); printf("Dealer: %i",Dealer); printf(" You can Hit(h), or stay(s): "); scanf("%s",action); Determine(); } else { printf("Player: %i ",Hand); printf("Dealer: %i",Dealer); printf(" You can Hit(h), or stay(s): "); scanf("%s",action); Determine(); } } } } // Generates a Random number between Min and Max int getrand(int Min,int Max){ return(rand()%(Max-Min)+Min); } #include <stdio.h> #include <time.h> #include <string.h> //Define All Global Variables Here int MinNumber,MaxNumber,Hand,Dealer,Turn; char action[20]; char *HitIt = "h"; char *Stay = "s"; char *DealIt = "d"; char *Quit = "q"; //Define All Functions Here int getrand(int min, int max); int srand(unsigned); int rand(); void Hit(); void Deal(); void PlayerHit(); void DealerHit(); void Determine(); int main(int argc, const char * argv[]) { MaxNumber = 11; MinNumber = 0; Hand = 0; Dealer = 0; Turn = 1; srand(time(NULL)); Deal(); Determine(); return 0; } // Gets two random numbers from 1 to 13 and adds them together and sets the Hand variable to it // Gets two random numbers from 1 to 13 and adds them together and sets the Dealer variable to it void Deal() { Hand = getrand(MinNumber,MaxNumber)+getrand(MinNumber,Max Number); Dealer = getrand(MinNumber,MaxNumber)+getrand(MinNumber,Max Number); Turn = 1; if(Dealer > 20 || Hand > 20) { printf(" Sorry but there was an error :( "); printf(" Player"); printf(" Dealer "); printf(" %i ",Hand); printf(" %i ",Dealer); } } // Adds a random number from 1-13 to the players hand variable void PlayerHit() { if(Turn == 1) { Hand += getrand(MinNumber, MaxNumber); } else { printf("Sorry But there was an error"); } } // Adds a random number from 1-13 to the dealers Dealer variable void DealerHit() { if(Turn == 0) { Dealer += getrand(MinNumber, MaxNumber); } else { printf("Sorry But there was a dealer error"); } } void Determine() { if(action != NULL) { if(strcmp(action,HitIt) == 0) { Turn = 1; PlayerHit(); } if(strcmp(action,Stay) == 0) { if(Dealer < 17) { Turn = 0; DealerHit(); } } if(strcmp(action,DealIt) == 0) { printf(" New Hand "); Deal(); } } if(Turn == 0) { if(Dealer < 17) { DealerHit(); Determine(); } else if((Dealer < Hand) && (Hand <= 21)) { DealerHit(); Determine(); } } // Start Determining who wins if(Hand == 21 && Dealer != 21) { printf("Player: %i Black Jack!! you Win ",Hand); printf("Dealer: %i",Dealer); printf(" Deal(d): "); scanf("%s",action); Determine(); } else if(Dealer == 21) { printf("Player: %i ",Hand); printf("Dealer: %i Black Jack!! Dealer Wins",Dealer); printf(" Deal(d): "); scanf("%s",action); Determine(); } else if(Hand > 21 && Dealer < 21) { printf("Player: %i you busted!! ",Hand); printf("Dealer: %i Dealer Wins",Dealer); printf(" Deal(d): "); scanf("%s",action); Determine(); } else if(Hand < 21 && Dealer > 21) { printf("Player: %i you Win ",Hand); printf("Dealer: %i Dealer busted!!",Dealer); printf(" Deal(d): "); scanf("%s",action); Determine(); } else if(Hand > 21 && Dealer > 21) { printf("Player: %i you Busted!! ",Hand); printf("Dealer: %i dealer busted!!",Dealer); printf(" Deal(d): "); scanf("%s",action); Determine(); } else { if(Turn == 1) { if(Dealer > Hand) { printf("Player: %i ",Hand); printf("Dealer: %i",Dealer); printf(" You can Hit(h), or stay(s): "); scanf("%s",action); Determine(); } else { printf("Player: %i ",Hand); printf("Dealer: %i",Dealer); printf(" You can Hit(h), or stay(s): "); scanf("%s",action); Determine(); } } } } // Generates a Random number between Min and Max int getrand(int Min,int Max){ return(rand()%(Max-Min)+Min); } Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.