Thread: Need Help With a BlackJack Program in C

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    8

    Post Need Help With a BlackJack Program in C

    Can anyone help me get started on this program, i have started it lightlybut seem to get a bit confused there after when i have to begin adding in new functions. The out put for this should look like this:

    Enter card (1-13): 1
    Enter card (1-13): 10
    Total(s): 11, 21
    Enter dealer's total: 21
    TIE

    Another game (1:Yes/0:No): 1
    Enter card (1-13): 11
    Enter card (1-13): 1
    Total(s): 11, 21
    Enter dealer's total: 17
    YOU WON!!

    Another game (1:Yes/0:No): 1
    Enter card (1-13): 10
    Enter card (1-13): 12
    Total(s): 20
    Another card (1:Yes/0:No): 0
    Enter dealer's total: 22
    YOU WON!!

    Another game (1:Yes/0:No): 1
    Enter card (1-13): 10
    Enter card (1-13): 8
    Total(s): 18

    Another card (1:Yes/0:No): 0
    Enter dealer's total: 20
    YOU LOST!!


    Another game (1:Yes/0:No): 1
    Enter card (1-13): 1
    Enter card (1-13): 1
    Total(s): 2, 12

    Another card (1:Yes/0:No): 1
    Enter card (1-13): 9
    Total(s): 11, 21
    Enter dealer's total: 17
    YOU WON!!

    Another game (1:Yes/0:No): 1
    Enter card (1-13): 2
    Enter card (1-13): 3
    Total(s): 5

    Another card (1:Yes/0:No): 1
    Enter card (1-13): 3
    Total(s): 8
    Another card (1:Yes/0:No): 1
    Enter card (1-13): 2
    Total(s): 10

    Another card (1:Yes/0:No): 1
    Enter card (1-13): 4
    Total(s): 14
    Another card (1:Yes/0:No): 1
    Enter card (1-13): 3
    Total(s): 17
    Another card (1:Yes/0:No): 0
    Enter dealer's total: 17
    TIE

    Another game (1:Yes/0:No): -1
    Error! Enter 1 for yes or 0 for no.
    Another game (1:Yes/0:No): 2
    Error! Enter 1 for yes or 0 for no.
    Another game (1:Yes/0:No): 1
    Enter card (1-13): 0
    Error card must be between 1 and 13!
    Enter card: 14
    Error card must be between 1 and 13!
    Enter card: 8
    Enter card (1-13): 2
    Total(s): 10
    Another card (1:Yes/0:No): -1
    Error! Enter 1 for yes or 0 for no.
    Another card (1:Yes/0:No): 2
    Error! Enter 1 for yes or 0 for no.
    Another card (1:Yes/0:No): 1
    Enter card (1-13): 1
    Total(s): 11, 21
    Enter dealer's total: 20
    YOU WON!!
    Another game (1:Yes/0:No): 0


    i dont have much as of yet but here is what i have so far:


    Code:
    #include <stdio.h>
    
    
    main()
    {
    int total;
    int card1, card2;
    int dealer;
    
    
    
            total = 0;
    
            printf("Enter Card (1-13): ");
            scanf("%d", &card1);
            printf("Enter Card (1-13): ");
            scanf("%d", &card2);
            total = card1 + card2;
            printf("Total(s): %d\n", total);
            printf("Enter Dealer's Total: ");
            scanf("%d", &dealer);
    
    }
    and required functions i need to be used are :
    int validateCard();
    int value(int card);
    void endResult(int Lost,highest total);
    int anotherCard();
    void totals(int total, int numAces, int *pLost, int *pHighestTotal);


    your help would be greatly appriciated!!

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    So what's your question? plz email me teh codez?

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    8
    which codes? like what i need to do?

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by Jp2009 View Post
    like what i need to do?
    Well... Write code, I'd guess...

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    8
    well my question is basically how do i get started using the functions i posted in the initial thread? i get screwed up also because when the card is 1 it is suppose to be ACE which can be 1 or 10 so i have to total it twice....and then ask the user if they would like another card

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Well, the names of the functions are clear indicators for what they should do, so what's keeping you from writing them?
    And the ace having 2 possible values is the entire reason of having the number of aces as a parameter in the total function.

  7. #7
    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

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

  9. #9
    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");
    }
    
    }

  10. #10
    Registered User
    Join Date
    Mar 2009
    Posts
    8
    i realize noone is going to write the code for me,
    but i dont quite understand what you suggested either, could you clarify it a bit?

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You have a function,

    validateCard(*c1, *c2)

    You have told the compiler that function will be like this:

    int validateCard()

    The actual function doesn't have a return, (but might return an int, that part is not specified), and has parameters of two pointers, going into it.

    Your prototype says the function will return an int, and has either no parameters going to it, or possibly one integer, you again, have not specified it correctly.

    You need the actual function, and the function's prototype, to be the same:

    either:

    void validateCard(int*, int*) or
    int(validateCard(void)
    or whatever you want it to be, but it needs to have the same return type (or no return), and the same parameters.

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