Need help with BlackJack program

This is a discussion on Need help with BlackJack program within the C Programming forums, part of the General Programming Boards category; im trying to write a blackjack program in c an it wont complie correctly here is my code and what ...

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    1

    Need help with BlackJack program

    im trying to write a blackjack program in c an it wont complie correctly
    here is my code and what the compiler errors are please go easy on me i'm new at this.
    insert
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    
    struct card
    {
    char rank[15];
    char suit[15];
    int value;};
    typedef struct card Card;
    struct deck
    {
    Card adeck[52];
    int top;
    };
    typedef struct deck Deck;
    struct player
    {
    double cash;
    double bet;
    Card hand[15];
    int count;
    };
    typedef struct player Player;
    
    
    char ranks[13][15]={"ace","king","queen","jack","ten","nine","eight","seven","six","five","four","three","two"};
    char suits[4][15]={"hearts","clubs","diamonds","spades"};
    int values[13]={11,10,10,10,10,9,8,7,6,5,4,3,2};
    int main()
    {
    Deck myDeck;
    Player me,dealer;
    Card c,dealerholdCard;
    double bet,cash;
    char answer[5];
    int i;
    for(i=0;i<52;i++)
    {
    strcpy(myDeck.aDeck[i].rank,ranks[i%13]);
    strcpy(myDeck.aDeck[i].suit,suits[i%4]);
    myDeck.aDeck[i].value=values[i%13];
    }
    myDeck.top=0;
    me.hand[i] = myDeck[top];
    myDeck.top++;
    me.count = me.hand[i].value;
    dealer.hand[i] = myDeck[top];
    myDeck.top++;
    dealer.count = dealer.hand[i].value;
    me.hand[i] = myDeck[top];
    myDeck.top++;
    me.count += me.hand[i].value;
    dealer.hand[i] = myDeck[top];
    myDeck.top++;
    dealer.count += dealer.hand[i].value;
    printf("your cards are %c of %c and %c of %c", me,hand[i].ranks,me.hand[i].suits,me.hand[i].ranks,me.hand[i].suits);
    printf("dealer showing %c of %c and %c of %c",dealer.hand[i].ranks,dealer.hand[i].suits,dealer.hand[i].ranks,dealer.hand[i].suits);
    
    
    if (me.count==21) 
    printf("you got 21 congrats");
    printf("play again?? press y for yes n for no"); //// finish code if yes restart game if no end game
    if (dealer.count==21) 
    printf("dealer has 21 game over. would you like to play again?? y for yes n for no");
    else
    printf("would you like to hit or stand?? h for hit s for stand");
    scanf("%c",&answer[i]);
    for(i=0;i<5;i++)
    {if(answer[i]='y' && (me.count<21 ))
    me.hand[i] = myDeck[top];
    myDeck.top++;
    me.count += me.hand[i].value;
    printf("your card is a %c of %c",me.hand[i].rank,me.hand[i].suit);
    if(me.count>21)
    printf("you bust. Play again??");
    scanf("%c",&answer[i]); // if answer is yes restart game if no end game
    for(i=0;dealer.count<17;i++)
    {if(answer[i]='n' && dealer.count<17)
    dealer.hand[i] = myDeck[top];
    myDeck.top++;
    dealer.count += dealer.hand[i].value;}
    if (dealer.count>21)
    printf("dealer busts would you like to play again??");
    scanf("%c",answer[i]);// if answer is yes restart game if no end game
    if(me.count> dealer.count)
    printf(" you win play again??");
    scanf("%c",answer[i]);
    if(me.count<dealer.count)
    printf("you lose play again??");
    scanf("%c",answer[i]);
    
    
    return 0;
    }
    }
    
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(39) : error C2039: 'aDeck' : is not a member of 'deck'
    1>        c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(12) : see declaration of 'deck'
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(39) : error C2228: left of '.rank' must have class/struct/union
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(40) : error C2039: 'aDeck' : is not a member of 'deck'
    1>        c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(12) : see declaration of 'deck'
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(40) : error C2228: left of '.suit' must have class/struct/union
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(41) : error C2039: 'aDeck' : is not a member of 'deck'
    1>        c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(12) : see declaration of 'deck'
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(41) : error C2228: left of '.value' must have class/struct/union
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(44) : error C2065: 'top' : undeclared identifier
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(47) : error C2065: 'top' : undeclared identifier
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(50) : error C2065: 'top' : undeclared identifier
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(53) : error C2065: 'top' : undeclared identifier
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(56) : error C2065: 'hand' : undeclared identifier
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(56) : error C2228: left of '.ranks' must have class/struct/union
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(56) : error C2039: 'suits' : is not a member of 'card'
    1>        c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(6) : see declaration of 'card'
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(56) : error C2039: 'ranks' : is not a member of 'card'
    1>        c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(6) : see declaration of 'card'
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(56) : error C2039: 'suits' : is not a member of 'card'
    1>        c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(6) : see declaration of 'card'
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(57) : error C2039: 'ranks' : is not a member of 'card'
    1>        c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(6) : see declaration of 'card'
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(57) : error C2039: 'suits' : is not a member of 'card'
    1>        c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(6) : see declaration of 'card'
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(57) : error C2039: 'ranks' : is not a member of 'card'
    1>        c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(6) : see declaration of 'card'
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(57) : error C2039: 'suits' : is not a member of 'card'
    1>        c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(6) : see declaration of 'card'
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(69) : error C2065: 'top' : undeclared identifier
    1>c:\users\darien\documents\visual studio 2008\projects\home\home\code.cpp(78) : error C2065: 'top' : undeclared identifier

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,344
    Please fix indentation Indent style - Wikipedia, the free encyclopedia

    Code becomes a lot easier to read/manage - You can clearly see where one thing starts and another ends

    From your errors
    'aDeck' : is not a member of 'deck'
    'top' : undeclared
    'suits' : is not a member of 'card'

    If you work through the errors, looking at the line number and the description of the error, it is not hard to figure out what is wrong
    Fact - Beethoven wrote his first symphony in C

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    2,292
    I hope this suggestion won't gum up your code, but (unless I'm missing it) the Ace can have two possible values.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Blackjack Program
    By turke92 in forum C Programming
    Replies: 8
    Last Post: 11-23-2011, 01:45 PM
  2. C program Blackjack
    By mjf_03 in forum Game Programming
    Replies: 7
    Last Post: 04-25-2011, 02:25 PM
  3. Need Help With a BlackJack Program in C
    By Jp2009 in forum C Programming
    Replies: 15
    Last Post: 03-30-2009, 10:06 AM
  4. blackjack program
    By mackieinva in forum C Programming
    Replies: 8
    Last Post: 09-20-2007, 03:46 AM
  5. Help with Blackjack program
    By sugie in forum C++ Programming
    Replies: 1
    Last Post: 04-30-2005, 12:30 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21