int main (void)
{
bool bPlayerDraw[5];
char cPlay = 'N';
char cCardDeck[4][13];
int iCard;
int iNumberOfDraws = 0;
int iSuit;
int iNumberOfPlayers = 0;
int iPlayerCount[5];
int iHighestCount = 0;
bool used[4][13];
char hand[5][5][2];
int k, m;
srand(GetTickCount());
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\n";
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 initCards(char CardDeck[][13],int& round,int& dealer,bool p[])
{
int i,k,m;
round=0;
dealer=rand()%4;
for(k=0;k<4;k++)
for(m=0;m<13;m++)
CardDeck[k][m]=' ';
for(i=0;i<5;i++)
p[i]=true;
}
int getPlayers()
{
int num;
cout<<"Welcome to Honest Sam's Blackjack Table\n";
cout<<"Glad to have you back!\n";
cout<<"Enter the number of players in the game.\n";
cout<<"only one player. no more than four.\n";
cout<<"Number of players: ";
cin>>num;
while(num<1||num>4)
{
cout<<"invalid entry\n";
cout<<"only one player. no more than four.\n";
cout<<"How many players in the game (1-4)? ";
cin>>num;
}
return num;
}
void deal(int players,char CardDeck[4][13])
{
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(CardDeck[l][k]!=' ');
CardDeck[l][k]=i;
}
}
void printcards(int players,char CardDeck[4][13],int round)
{
int i,j,k;
string card[]={"2","3","4","5","6","7","8","9","10","jack","queen","king","ace"};
int code[]={4,3,5,6};
bool d=false;
if(round==100)
d=true;
for(i=0;i<=players;i++)
{
if(i==0)
cout<<"Dealers hand\n";
else
cout<<"Player "<<i<<"s hand\n";
for(j=0;j<4;j++)
for(k=0;k<13;k++)
if(CardDeck[j][k]==i)
if(i!=0||d)
cout<<(char)code[j]<<" "<<card[k]<<endl;
else
d=true;
}
}
The errors are caused by incorrect placement of braces. For example the brace on line 95 tells the compiler that that is the end of the function, although you don't mean to say that. Just indent your code properly, and the incorrect braces will appear.
That's technically correct, but not clear and difficult to read. Therefore always surround the bodies of if-statements and loops with braces, even if you only have one statement.
Result:
1 2 3 4 5 6 7 8 9 10
for ( i = 0; i < 4; i++ )
{
for ( j = 0; j < 13; j++ )
{
if ( !used[ i ][ j ] )
{
cout << ( char ) code[ i ] << " " << card[ j ] << endl;
}
}
}