Please Help w/ Messy Poker Program

This is a discussion on Please Help w/ Messy Poker Program within the C++ Programming forums, part of the General Programming Boards category; How would i "name" the cards in the array using a switch statement( such as King of Hearts, 4 of ...

  1. #1
    ray
    ray is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    14

    Question Please Help w/ Messy Poker Program

    How would i "name" the cards in the array using a switch statement( such as King of Hearts, 4 of Spades etc.)? How would I actually show them the cards i dealt out, this is only my 3rd week of class. Please help. All this program is supposed to do is make a simple poker game w/ no straights or flushes.


    #include <iostream.h>
    #include <string.h>
    #include <ctype.h>
    const int PLAYERNUM=2;

    void shuffle (int wDeck [4][13]);
    void deal (int wDeck[4][13], int wHand[PLAYERNUM][4][13]);
    void main ()
    {
    #define PLAYERNUM 2
    int deck[4][13]={0};
    int player;
    int hand[PLAYERNUM][4][13]={0};

    char s, d;

    cout<<"Welcome to five card poker with no straights or flushes. "<<endl;


    cout<<"Press s to shuffle"<<endl;
    cin>>s;
    shuffle(deck);

    cout<<"Press d to deal the cards"<<endl;
    cin>>d;

    deal (deck, hand );

    cout<<"player one, your cards are"<<endl;



    //dont know what else to do here






    return;
    }

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

    for (cardnum=1; cardnum<=52; cardnum++)
    {
    row=rand()%4;
    column=rand()%13;

    while (wDeck[row][column]!=0)
    {
    row=rand()%4;
    column=rand()%13;
    }
    wDeck[row][column]=cardnum;
    }
    }




    void deal (int wDeck[4][13], int wHand[PLAYERNUM][4][13])
    {
    int cardnum, row, column, firstCard=1, lastCard=5, flag=0;

    for (int hand=0; hand<PLAYERNUM; hand++)
    {
    for (cardnum=firstCard; cardnum<=lastCard; cardnum++)
    {
    for (column=0; column<13; column++)
    {
    if (wDeck[row][column]==wDeck[row][column])
    {
    wHand[hand][row][column]=wDeck[row][column];
    flag=1;
    break;
    }
    }
    if (flag==1)
    {
    flag=0;
    break;
    }
    }
    firstCard+=5;
    lastCard+=5;
    }
    return;
    }

  2. #2
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    about "switch" statement, you can use what is called enumaraion:
    i.e:

    Code:
    enum cards{hearts = 1, diamonds, spades, clubs};
    
    int choice;
    
    cout << "enter choice: ";
    cin >> choice;
    
    switch(choice)
    {
         case hearts: cout << "hearts"; break;
         
         case diamonds: cout << "diamonds"; break;
    
         case spades: cout << "spades"; break;
    
         case clubs:   cout << "clubs"; break;
    
         default:  cout << "wrong choice"; 
    }
    also to make some nice visuals in console programming, you can look up an ASCII character chart on the internet (characters from 0-255) and somewhere in higher hundreds you have characters that stand for all 4 cards and will make your output nicer visually...

    good luck....

    matheo917

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why doesn't this poker C program work?
    By hermancarson in forum C Programming
    Replies: 5
    Last Post: 04-09-2008, 09:58 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, 10:17 PM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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