Thread: card shuffling array(help!!!!!!!!!)

  1. #1

    Unhappy card shuffling array(help!!!!!!!!!)

    i have this program that i need to complete but i cant seem to figure it out. i have to create teh program to deal 5 cards(which it does that) and then it has to disply these fowlling things:
    -determine if the hand contains a pair
    -determine if the hand contains two pairs
    -determine if the hand contains three of a kind
    -determine if the hand contains four of a kind
    -determine if the hand contains a flush
    -determine if the hand contains a straight

    heres the code if your guys could greatly help me out i would appreciate it im so confused!!!


    void shuffle(int [] [ 13 ]);
    void deal(const int [] [ 13 ], const char *[], const char *[]);

    int main()
    const char *suit[ 4 ] =
    {"hearts", "diamonds", "clubs", "spades" };
    const char *face[ 13] =
    {"ace", "deuce", "three", "four", "five", "six",
    "seven", "eight", "nine", "ten", "jack", "queen", "king"};

    int deck[4][13] = {0};


    deal(deck, face, suit);

    return 0;

    void shuffle(int wDeck[] [13])
    int row, column;

    for (int card = 1; card <= 5; card++){
    do {
    row = rand() % 4;
    column = rand() % 13;
    } while (wDeck[row][column] !=0);

    wDeck[row][column] = card;

    void deal (const int wDeck[] [13], const char *wFace[],
    const char *wSuit[])
    for (int card = 1; card <= 5; card++)

    for (int row = 0; row <=3; row++)

    for (int column = 0; column <= 12; column++)

    if (wDeck[row][column] == card){

    <<wFace[column]<<" of "
    <<(card % 2 == 0 ? '\n' : '\t')<<endl;


  2. #2
    Frustrated Programmer :( phantom's Avatar
    Join Date
    Sep 2001
    I see you are using my favourite text book (either that or it is very similar question). Deitel & Deitel 'programming for C++' would be the best text out there. In fact for college we had to do that very program and the question you ask was extra work.
    If my memory serves me correct you use a for loop to compare the strings. I will admit that it gets very confusing very fast, I only succeeded in finding out if 2 or more cards in the hand were the same
    Sorry I can't help you more but I seemed to have lost my code from that project

  3. #3
    Registered User alex's Avatar
    Join Date
    Sep 2001

    You are making things more difficult than they are. Whay do you use a twodimensional array "deck"? I would just create a simple array of 52 elements, and fill it with values 0...51. Then you can find out which card belongs to this number by doing this:

    const char *suit[4] = {"hearts", "diamonds", "clubs", "spades"}; 
    const char *face[13] = {"deuce", "three", "four", "five", "six", "seven", 
          "eight", "nine", "ten", "jack", "queen", "king", "ace"};
    for(card=0; card<52; card++)
       printf("Card %i is: %s of %s.\n", card, face[card/4], suit[card%4]);

    Hope this helps...

  4. #4
    Registered User
    Join Date
    Aug 2001
    Warpedone is probably doing that because that's how it's set up in the Deitel textbook. Part of the exercise is demonstrating two dimensional arrays.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitwise Unwanted Output
    By pobri19 in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2008, 04:07 AM
  2. Vector out of range program crash.
    By Shamino in forum C++ Programming
    Replies: 11
    Last Post: 01-18-2008, 05:37 PM
  3. Segmentation Fault - aaaaaaaah!
    By yogibear in forum C Programming
    Replies: 6
    Last Post: 10-01-2007, 03:21 AM
  4. Blackjack
    By Tommo in forum C Programming
    Replies: 10
    Last Post: 06-20-2007, 08:07 PM
  5. How can I access a struct (from a header file)?
    By loxslay in forum C++ Programming
    Replies: 3
    Last Post: 10-07-2006, 01:25 PM