CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2013
    Posts
    1

    Help with errors Please

    I have to build a blackjack code and i have most of it done but now i cant figure out what the error messages mean. I know its pretty basic but i could use all the help i can get.
    here is the original code...

    HTML Code:
    #include <string>
    #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
    {
    int i,j,k,l;
    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;
    } }

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Help with errors Please

    1) Please format your code properly, as it is practically unreadable as it is. It is all flushed to the left hand margin, and I hope you didn't actually right the code this way. Use the code tags (not HTML tags)

    2) Why are you including <windows.h> when there are no Windows API calls or usage of Windows API constants?

    Regards,

    Paul McKenzie

  3. #3
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Help with errors Please

    You have quite a lot of compile time errors. Some of these are due to missing/extra braces which would be fairly easy to spot if you formatted and indented the code properly. You also have multiple definitions of some functions (eg printdeck) and use some undefined identifiers (eg k, l, n in the first printdeck - which code probably shouldn't be there at all as why is it changing cardDeck in a print function?).

    I would suggest that you format your code and indent it as appropriate, then examine it carefully for the issues I've mentioned above. This should fix most of the compile errors, and any left should be easy to identify and solve.

    2) Why are you including <windows.h> when there are no Windows API calls or usage of Windows API constants?
    Because of the use of GetTickCount to seed srand().
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Help with errors Please

    Quote Originally Posted by 2kaud View Post
    Because of the use of GetTickCount to seed srand().
    OK. But since this is a non-Windows forum:
    Code:
    srand(time(NULL));
    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured