Thread: Need Help With a BlackJack Program in C

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Why don't you try writing at least one function (in fact, a Very Good Idea is to only do one function at a time, and make sure it works before you move on)...if you have a problem with that, then post the code. I don't think anyone will just write a function from scratch for your blackjack game.

    If you are having problems just with the idea of "writing a function" (your Original Post does not include any), then the issue of what the functions are supposed to be called, etc. is kind of irrelevent; you need to ask more specific questions...
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    8
    ok thanks,

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    8
    ok so this is what i have created so far but i cant get it to compile yet, i still have a couple functions to add.... any suggestions as to what i am doing wrong so far??

    Thanks,


    Code:
    #include <stdio.h>
    int validateCard();
    int value(int care);
    void endResult(int Lost,highest total);
    int anotherCard();
    void totals(int total, int numAces, int *pLost, int *pHighestTotal);
    
    
    main()
    {
    int card1, card2, total, dtotal;
    
    printf("Enter card: \n");
    scanf("%d" , &card1);
    printf("Enter card: \n");
    scanf("%d" , &card2);
    
    validateCard(card1, card2);
    
    total = card1 + card2;
    
    printf("%d" , total);
    
    printf("Enter dealer total: \n");
    scanf("%d" , &dtotal);
    
    endResult(total, dtotal);
    
    
    
    int validateCard(*c1, *c2){
    if (card1 > 10)
    card1 = 10;
    if (card2 > 10)
    card1 = 10;
    }
    
    
    void endResult{
    if (total > dtotal)
    printf("You Win");
    
    else if(dtotal > total)
    printf("You Lose");
    
    else
    printf("Tie");
    }
    
    }

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by Jp2009 View Post
    ok so this is what i have created so far but i cant get it to compile yet,
    1. post compilation errors
    2. indent your code
    3. use int main(void) - read FAQ why
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    8
    Code:
    #include <stdio.h>
    int validateCard();
    int value(int care);
    void endResult(int Lost,highest total);
    int anotherCard();
    void totals(int total, int numAces, int *pLost, int *pHighestTotal);
    
    
    main(void)
    {
    int card1, card2, total, dtotal;
    
         printf("Enter card: \n");  
         scanf("%d" , &card1);
         printf("Enter card: \n");
         scanf("%d" , &card2); 
    
    validateCard(card1, card2);
    
    total = card1 + card2;
    
          printf("%d" , total);
    
          printf("Enter dealer total: \n");
          scanf("%d" , &dtotal);
    
    endResult(total, dtotal);
    
    
    
    int validateCard(*c1, *c2){
        
         if (card1 > 10)
         card1 = 10;
         if (card2 > 10) 
         card1 = 10;
    }
    
    
    void endResult{
    
        if (total > dtotal)
        printf("You Win");
    
    
        else if(dtotal > total)
        
        printf("You Lose");
    
    else
        printf("Tie");
    }
    
    }



    and the compiling errors are:

    bj1.c:4: error: expected declaration specifiers or '...' before 'highest'
    bj1.c: In function 'main':
    bj1.c:27: error: too many arguments to function 'endResult'
    bj1.c:31: error: expected declaration specifiers or '...' before '*' token
    bj1.c:31: error: expected declaration specifiers or '...' before '*' token
    bj1.c:39: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The compiler is terribly confused.
    Code:
    void endResult(int Lost,highest total);
    what is "highest"? The placement of it suggest to the compiler that you have a type called highest. But there is no declaration of such a type yet.

    Code:
    int validateCard();
    ...
    validateCard(card1, card2);
    ...
    int validateCard(*c1, *c2)
    So first you say that validateCard takes an arbitrary number of arguments (or no arguments in C++), then that you pass two int arguments, and then you say that it takes to pointers.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Mar 2009
    Posts
    8
    Code:
    #include <stdio.h>
    int validateCard();
    int value(int card);
    void endResult(int Lost, highestTotal);
    int anotherCard();
    void totals(int total, int numAces, int *pLost, int *pHighestTotal);
    
    
    int main(void)
    {
    int card1, card2, total, dtotal;
    int newgame, int another;
    
    printf("Enter card: \n");
    scanf("%d" , &card1);
    printf("Enter card: \n");
    scanf("%d" , &card2);
    
    validateCard(card1, card2);
    
    total = card1 + card2;
    
    printf("%d" , total);
    
    printf("Enter dealer total: \n");
    scanf("%d" , &dtotal);
    
    if (total < 16 || total > 27)
    printf("Error Card Must Be Between 1 and 13!");
    
    endResult(total, dtotal);
    
    
    
    int validateCard(*c1, *c2){
    if (card1 > 10)
    card1 = 10;
    if (card2 > 10)
    card1 = 10;
    }
    
    
    int anotherCard(another);
    printf("Another Card? (1:Yes/0:No)");
    scanf("%d", &another);
    if(another==1)
    /* i need this to go back to main to prompt for a new card*/
    
    else if
    (another==0)
    /* i need this to go to the dealers total*/
    void endResult{
    
    if (total > dtotal)
    printf("You Win");
    
    else if(dtotal > total)
    printf("You Lose");
    
    else
    printf("Tie");
    }
    
    printf("Another Game? 1:Yes/0:No");
    scanf("%d", &newgame);
    if (newgame==1)
    /* i need this to loop the game all over again*/
    else if
    (newgame==0)
    /* i need this to end the game*/
    
    }
    if anyone can help me figure this out it would be great, also i need int numAces to have it when a the number equals 1 for ace to have it calculate ace as 1 and 11 - i have no idea how to do this so if anyone can help again please that would be awsome!
    thanks,

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. blackjack program
    By mackieinva in forum C Programming
    Replies: 8
    Last Post: 09-20-2007, 03:46 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM