• 0

[C++] Card Dealing Program


Question

Ok the program is supposed to deal 5 cards out to 4 players. I'm just beginning so try to keep that in mind when giving advice that things like 2D arrays which would be extremely useful in this scenario are not an option. So I first filled an array with 0-51 to make the deck. I then shuffled the deck and handed it out to the 4 players. Now I have some numbers printed out as cards in the players hand. I need to make it so those numbers are somehow changed to suits/and numbered cards. To do this I play to use card[n]/13 to give me 0,1,2,3 then each of those numbers will signify a suit. Then do (card[n]%13)+1 to determine what card it is...(1=ace, 11=Jack, 12 = Queen, 13 = King). The problem I am having is implementing this into the program. If someone could point me in the direction I would be very appreciative.

This is the source http://www.seanhelp.pastebin.com/m2b2a34b6

Edited by Sean123
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Your method looks fine so far. I've been doing something almost identical for an assignment for University (the memory game called Pairs/Pelanism)

For the suits and card values I used enumerations (not sure if you've came across them). Basically they're a quick way to do multiple defines.

// Enumerations of card values
 enum Value {
	 ACE = 1, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING
 };

 // Enumeration of suits
 enum Suit {
	 SPADES = 0, CLUBS, HEARTS, DIAMONDS
 };

Because my implementation is C++ using object orientated methods I've got this information within a class but you could then add functions such as

char getSuit(int);

and

char getValue(int);

This could be used to return you the suit in a letter form such as 'S', 'C' etc and a value for the card equal to 2-A. Hope this helps. Post back if you're unclear about anything I've said or have more questions!

Link to comment
Share on other sites

  • 0
Your method looks fine so far. I've been doing something almost identical for an assignment for University (the memory game called Pairs/Pelanism)

For the suits and card values I used enumerations (not sure if you've came across them). Basically they're a quick way to do multiple defines.

// Enumerations of card values
 enum Value {
	 ACE = 1, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING
 };

 // Enumeration of suits
 enum Suit {
	 SPADES = 0, CLUBS, HEARTS, DIAMONDS
 };

Because my implementation is C++ using object orientated methods I've got this information within a class but you could then add functions such as

char getSuit(int);

and

char getValue(int);

This could be used to return you the suit in a letter form such as 'S', 'C' etc and a value for the card equal to 2-A. Hope this helps. Post back if you're unclear about anything I've said or have more questions!

You are right (Y)

Instead of using pack of cards as collection of 52 playing cards........... segregate them into 4groups each of 13cards

So your code process should like this

1. give out the players a randomize suit (ie there are only four possibilities)

2. if u have done that.... call a function within this loop to get your random card (1-13 ie ace to king)

3. Clubbing both steps above u know which player has what suit and its value

Hope that would help :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.