You are using a version without Ads of this website. Please, consider donating:

### Black Jack game

Hello,

I need some help. I am in a C++ class and we need to build a blackjack game. The professor provided some code for us to fill in the blanks. I just can't get my head around a piece of it. I'll try to post the whole thing, but may not be space.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193`` ``````#include #include #include using namespace std; int main(void) { bool bPlayerDraw[5] = {0}; //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 [13] = {0}; //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 [4] = {0}; //Suit array index //0 = diamonds //1 = hearts //2 = clubs //3 = spades 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 do { cout << endl << "Welcom to Honest Sam's Black Jack Table" << endl << endl; cout << "Press Y or y to play or any other key to exit game: "; cin >> cPlay; if(cPlay != 'Y' && cPlay != 'y') { return (0); // complete this } for(k = 0; k < 4; k++) { for(m = 0; m < 13; m++) { cCardDeck[k][m] = iCard [m] + iSuit[k]; // complete this } } for(k = 0; k < 5; k++) { iPlayerCount[k] = 0; bPlayerDraw[k] = 1; // complete this } iNumberOfDraws = 0; iHighestCount = 0; system("cls"); cout << "Welcome to Honest Sam's Black Jack Table" << endl << endl; cout << "Glad to have you back!" << endl << endl; do { cout << "How many people would like to play?" << endl; cout << "Enter the number of Players: "; cin >> iNumberOfPlayers; // complete this } while(iNumberOfPlayers < 1 || iNumberOfPlayers > 4); cout << endl << endl; cout << " Dealer "; for(k = 0; k < iNumberOfPlayers; k++) //Display Dealer and Player # header for card output display { cout << " Player " << k+1; } while(iNumberOfDraws < 5) { iNumberOfDraws++; cout << endl << "Card " << iNumberOfDraws << ": "; for(k = 0; k < iNumberOfPlayers + 1; k++) //Loop for card drawing, player hold, card display and count totals { do { iSuit = rand()%4; iCard = rand()%13; } while(cCardDeck[iSuit] [iCard] != ' '); if(bPlayerDraw[k] == true) { cCardDeck[iSuit[],iCard[]] = k + 48; //Store ASCII number of player in card deck array to indicate which //player drew the card if(iCard < 8) //Calculate card count //Note Aces have been set = 11, not 1 or 11, maybe later... iPlayerCount[k] += iCard [8] + 2; else if(iCard == 8 || iCard < 12) ......// complete this else ......// complete this if(iPlayerCount[k] == 21 || iPlayerCount[k] > 18 - rand()%3) { //Use random number to determine whether to draw another card ...... if(iCard < 9) //Output card cout << setw(9)<< iCard + 2; else if (iCard == 9) cout << setw(9)<< "J"; else if (iCard == 10) cout << setw(9)<< "Q"; else if (iCard == 11) cout << setw(9)<< "K"; // complete this else cout << setw(9)<< "A" // complete this } //Output symbol for card suit cout << char(iSuit+3); } else cout << " Hold"; } } cout << endl << endl << "Final: "; //Output final count for each iPlayerCount for(k = 0; k < iNumberOfPlayers + 1; k++) { .....// complete this cout << endl << " "; } //Find highest winning count for(k = 0; k < iNumberOfPlayers + 1; k++) { if(iPlayerCount[k] > iHighestCount && iPlayerCount[k] <= 21) iHighestCount = iPlayerCount[k]; } //Output whether dealer and players won or lost for(k = 0; k < iNumberOfPlayers + 1; k++) { if(iPlayerCount[k] == iHighestCount) cout << endl << endl << "Player number " << iPlayerCount[k] << " you win!"; // complete this else cout << endl << endl <<"Player number " << iPlayerCount [k] << " you are a looser!"; // complete this } //Display entire drawn deck to check if an honest game //What happens in Vegas or KC might not stay there... cout << endl << endl << endl << "Display entire card deck, rows = suits, columns = card"; cout << endl << "0 = dealer card, 1 = Player 1 card, 2 = Player 2 card, etc."; cout << endl << endl << " "; for(k = 0; k < 13; k++) { if(k < 9) cout << setw(3)<< k + 2; else if (k == 9) cout << setw(3)<< "J"; else if (k == 10) cout << setw(3)<< "Q"; // complete this else if (k == 11) cout << setw(3)<< "K"; // complete this else cout << setw(3)<< "A"; // complete this } cout << endl; for(k = 0; k < 4; k++) { cout << setw(3) << char(k+3); for(m = 0; m < 13; m++) { cout << setw(3) << cCardDeck[k][m]; } cout << endl; } cout << endl << endl; } while(1); cin.ignore (2); }``````

My problem is lines 111 to 116.
 ``12345`` ``````do { iSuit = rand()%4; iCard = rand()%13; }``````

I'm just not getting it

Thanks for any help
Last edited on
Topic archived. No new replies allowed.

You are using a version without Ads of this website. Please, consider donating: