help with errors

Can someone check this code out and help me fix the errors. I'm pretty rusty at this and cannot figure it out
Thanks


#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];
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 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\n";
else
cout<<"Player "<<i<<"s hand\n";
for(j=0;j<5;j++)
{
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\n";
for(i=0;i<4;i++)
for(j=0;j<13;j++)
if(!used[i][j])
cout<<(char)code[i]<<" "<<card [j]<<endl;
}
do
{
k=rand()%13;
l=rand()%4;
}
while(CardDeck[l][k]!=' ');
CardDeck[l][k]=n;
}

void scoreCards(char c[4][13],int s[],int n)
{
int i,j,k,aces=0;
for(i=0;i<=n;i++)
{
aces=0;
s[i]=0;
for(j=0;j<4;j++)
for(k=0;k<13;k++)
{
if(c[j][k]==i)
if(k<9)
s[i]+=(k+2);
else if(k<12)
s[i]+=10;
else
aces++;
if(aces>0)
if(aces>1)
s[i]+=aces;
else
if(s[i]+11>21)
s[i]++;
else
s[i]+=11;
}
cout<<i<<" "<<s[i]<<" "<<j<<" "<<k<<endl;
}
}

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;
}
}

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\n";
else
cout<<"Player "<<i<<"s hand\n";
for(j=0;j<5;j++)
{
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\n";
for(i=0;i<4;i++)
for(j=0;j<13;j++)
if(!used[i][j])
cout<<(char)code[i]<<" "<<card[j]<<endl;
}
What are the error messages you're getting?
And by the way, when posting code, select it and press the <> button.
Sorry and thank you for the help. Here is the error code list.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(97) : error C2059: syntax error : 'do'
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(98) : error C2143: syntax error : missing ';' before '{'
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(98) : error C2447: '{' : missing function header (old-style formal list?)
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(102) : error C2059: syntax error : 'while'
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(103) : error C2065: 'l' : undeclared identifier
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(103) : error C2065: 'k' : undeclared identifier
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(103) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(103) : error C2065: 'n' : undeclared identifier
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(104) : error C2059: syntax error : '}'
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(104) : error C2143: syntax error : missing ';' before '}'
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(104) : error C2059: syntax error : '}'
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(107) : error C2143: syntax error : missing ';' before '{'
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(107) : error C2447: '{' : missing function header (old-style formal list?)
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(183) : error C2601: 'printcards' : local function definitions are illegal
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(215) : error C2065: 'used' : undeclared identifier
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(216) : error C2065: 'hand' : undeclared identifier
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(217) : error C2065: 'hand' : undeclared identifier
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(218) : error C2065: 'used' : undeclared identifier
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(223) : error C2601: 'printcards' : local function definitions are illegal
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(241) : error C2601: 'printdeck' : local function definitions are illegal
1>y:\d01321185\documents\visual studio 2008\projects\calderon_lab01\calderon_lab01\calderon_lab01.cpp(251) : fatal error C1004: unexpected end-of-file found
1>Build log was saved at "file://\\ilabss\home$\D01321185\Documents\Visual Studio 2008\Projects\Calderon_lab01\Calderon_lab01\Debug\BuildLog.htm"
1>Calderon_Lab01 - 23 error(s), 4 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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\n";
    for(i=0;i<4;i++)
        for(j=0;j<13;j++)
            if(!used[i][j])
                cout<<(char)code[i]<<" "<<card [j]<<endl;
}
do
{
    k=rand()%13;
    l=rand()%4;
}
while(CardDeck[l][k]!=' ');
CardDeck[l][k]=n;
}


Go to the line of the first error. Look at the previous lines. Does anything look out of place?


Could it be the fact that lines 97 to 104 are outside of any function body?

You'll also want to #include <string> to get rid of the first error that you elided.
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.

Also some advice:
This is your code:
1
2
3
4
for(i=0;i<4;i++)
for(j=0;j<13;j++)
if(!used[i][j])
cout<<(char)code[i]<<" "<<card [j]<<endl;

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;
        }
    }
}


Looks a lot nicer, isn't it? :)
Last edited on
Topic archived. No new replies allowed.