BlackJack card help

This is a discussion on BlackJack card help within the Game Programming forums, part of the General Programming Boards category; Ok, I am making a BlackJack game in console (there's a way, believe me), and would like to know how ...

  1. #1
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644

    BlackJack card help

    Ok, I am making a BlackJack game in console (there's a way, believe me), and would like to know how to display the card values randomly. I have an array like this:
    Code:
    int card_values[13] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
    And my card choosing code goes like this:
    Code:
    srand(time(NULL));
    	for(card_p_1 < )
    	{
    		while(card_p_1 < 5)
    		{
    			cout << card_values[13];
    		}
    	}
    I have card_p_1 defined already before the code, but this is what happens:
    Code:
    --------------------Configuration: black jack - Win32 Debug--------------------
    Compiling...
    main.cpp
    C:\Program Files\MVC\MyProjects\black jack\main.cpp(26) : error C2374: 'card_values' : redefinition; multiple initialization
            c:\program files\mvc\myprojects\black jack\arrays.h(6) : see declaration of 'card_values'
    C:\Program Files\MVC\MyProjects\black jack\main.cpp(26) : error C2440: 'initializing' : cannot convert from 'int' to 'int []'
            There are no conversions to array types, although there are conversions to references or pointers to arrays
    C:\Program Files\MVC\MyProjects\black jack\main.cpp(172) : error C2059: syntax error : ')'
    C:\Program Files\MVC\MyProjects\black jack\main.cpp(173) : error C2143: syntax error : missing ';' before '{'
    C:\Program Files\MVC\MyProjects\black jack\main.cpp(176) : error C2059: syntax error : ';'
    Error executing cl.exe.
    
    black jack.exe - 5 error(s), 0 warning(s)
    I've tried numerous things (about 6 things approximently). Any help would be greatly appreciated.

    EDIT: Here's the declarations:
    Code:
    int card_d_1, card_d_2, card_p_1, card_p_2;
    int card_values[] = card_values[13];
    Last edited by Quantrizi; 08-22-2002 at 01:34 PM.

  2. #2
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    for(card_p_1 < )

    I do not understand that.

  3. #3
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    My code got screwed up for some reason. Here's the updated code:
    Code:
    srand(time(NULL));
    	while(card_p_1 < 5)
    	{
    		srand(time(NULL));
    		int card = rand()% card_values[];
    		cout << card;
    	}
    and the errors:
    Code:
    --------------------Configuration: black jack - Win32 Debug--------------------
    Compiling...
    main.cpp
    C:\Program Files\MVC\MyProjects\black jack\main.cpp(26) : error C2440: 'initializing' : cannot convert from 'int' to 'char []'
            There are no conversions to array types, although there are conversions to references or pointers to arrays
    C:\Program Files\MVC\MyProjects\black jack\main.cpp(175) : error C2059: syntax error : ']'
    Error executing cl.exe.
    
    black jack.exe - 2 error(s), 0 warning(s)

  4. #4
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    I think this is the problem:

    int card_values[] = card_values[13];

    card_values[] is a pointer, car_values[13] is a integer.

  5. #5
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    This may be a problem too:

    int card = rand()% card_values[];

    card is an int, rand() returns an int. You have int modulos pointer. I do not understand that.

  6. #6
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    This may be a problem too:

    int card = rand()% card_values[];

    card is an int, rand() returns an int. You have int modulos pointer. I do not understand that.
    It was supposed to output a random "card" from the array card_values. Which is one problem, but I dunno how to fix it.
    I think this is the problem:

    int card_values[] = card_values[13];

    card_values[] is a pointer, car_values[13] is a integer.
    card_values[] is supposed to be card_value[]. Again, dunno how to fix it. I thought using the code:
    int card_value[] = card_values[13] would work (car_values is supposed to be card_values)

  7. #7
    no-one
    Guest
    >int card = rand()% card_values[];

    is not legal

    try

    int card = rand()% card_values[0]; // you need to index the array

  8. #8
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Ok, I thought I had to do that, but I that that might not be legal...one question though....how would that randomize the card number (value) output?

  9. #9
    no-one
    Guest
    ahh i see, sorry.

    you probably should define a value as the number of cards and use it.

    #define CARDS_PER_SUIT 13 // or something more creative

    int card = rand()%CARDS_PER_SUIT;

    are you determining the suit elsewhere?

  10. #10
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Nope. Right now I'm just dealing with the card numbers, then I'm gonna use the card code to for the card suit.

  11. #11
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Ok, I tried your idea no-one, and it sorta works. It now works better than before, but only outputs 1 card. I'm gonna see if I can fix it.
    [EDIT] The new problem is that it floods the screen with that number generated by the rand()%cards_per_suit (cards_per_suit is defined as 13). If anyone wants to exactly see the error, I'll upload the exe for anyone.
    Last edited by Quantrizi; 08-22-2002 at 03:54 PM.

  12. #12
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    you could always go:

    int card = card_values[rand()%13];
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  13. #13
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Ok, thanks. I'll try that

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rolodex(information manager) =>Check my Code
    By jackfraust in forum C++ Programming
    Replies: 3
    Last Post: 04-26-2009, 03:41 AM
  2. Need Help With a BlackJack Program in C
    By Jp2009 in forum C Programming
    Replies: 15
    Last Post: 03-30-2009, 10:06 AM
  3. Bitwise Unwanted Output
    By pobri19 in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2008, 04:07 AM
  4. Vector out of range program crash.
    By Shamino in forum C++ Programming
    Replies: 11
    Last Post: 01-18-2008, 04:37 PM
  5. Segmentation Fault - aaaaaaaah!
    By yogibear in forum C Programming
    Replies: 6
    Last Post: 10-01-2007, 03:21 AM

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