BlackJack help

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <iostream>
#include <iomanip>
#include <windows.h>

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.
1
2
3
4
5
do
				{
					iSuit = rand()%4;
					iCard = rand()%13;
				}


I'm just not getting it

Thanks for any help
closed account (3qX21hU5)
Basically what the lines are doing is they are assigning a number 1 - 4 to Isuit (Which will represent the suit of the card like 1 = hearts, 2 = Diamonds, ect). It also assigns a random number 1 - 13 to iCard which will resprent the number on the card 13 meaning Ace I assume 12 meaning King, ect.
are you not understanding the modulo basically it is saying it picks a random number then divides by 4/13 and suit/card is the remainder value

eg 10 % 4 would be 2 since 10/4 would have a remainder of 2 4*2 = 8 10-8 = 2.
Thanks for the comments, but maybe I should have clarified. I understand what the logic is, but I don't know what problem with the syntax is. In the sample (lines 94 to 99) how is the random number value assigned to the array elements? It isn't running inside of a loop so that I could use the index value as the value for the array element.
Topic archived. No new replies allowed.