Thread: Poker Game

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Poker Game

    Write a program to play poker! You can provide 5 cards to the player, let that player choose new
    cards, and then determine how good the hand is. Think about whether this is easy to do. What problems
    might you have in terms of keeping track of cards that have been drawn already?

    I have done this below so far except I will have a problem with keeping track of cards that have already been drawn. Also I'm not sure how to account for cards such as ace, king, queen, jack. Should I use an enumeration?

    Code:
    #include <iostream> //include header files
    #include <cstdlib>
    #include <ctime>
    
    
    using namespace std;
    
    
    int card1()
    {
        srand(time(NULL));
        return (rand()%52)+1;
    }
    int card2()
    {
        return (rand()%52)+1;
    }
    int card3()
    {
       return (rand()%52)+1;
    }
    int card4()
    {
        return (rand()%52)+1;
    }
    int card5()
    {
        return (rand()%52)+1;
    }
    
    
    
    
    int main ()
    {
        int card_one = card1();
        int card_two = card2();
        int card_three = card3();
        int card_four = card4();
        int card_five = card5();
    
    
        cout << card_one << " : " << card_two << " : " << card_three << " : " << card_four << " : " << card_five << endl;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well here's a couple of ideas.

    1. A card
    Code:
    class card {
        int rank;
        enum { HEART, CLUB, DIAMOND, SPADE } suit;
    };
    2. A deck
    Code:
    class deck {
      card cards[52];
      void shuffle();
      card deal();
    };
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    36
    thanks for the help. I have been doing the ebook from this website and am not supposed to use classes as it is a later chapter in the book. Is there a way to do it without classes? if not I'll the classes chapter a read and have a go.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Sure, you could do it with just
    int deck[52];

    But you still should have the idea of shuffling and dealing within your code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Mar 2013
    Posts
    36
    thanks will give it a go.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Poker Game need help...
    By boyracer88 in forum Game Programming
    Replies: 1
    Last Post: 11-25-2005, 01:32 PM
  2. Poker Game
    By egomaster69 in forum C Programming
    Replies: 18
    Last Post: 01-03-2005, 06:24 PM
  3. poker game
    By b00l34n in forum Game Programming
    Replies: 14
    Last Post: 01-03-2005, 12:21 PM
  4. Poker Game
    By Smiley**123 in forum Game Programming
    Replies: 6
    Last Post: 12-14-2003, 09:48 AM
  5. poker game help
    By datainjector in forum C Programming
    Replies: 5
    Last Post: 09-06-2002, 07:31 AM