Question: I need some help in writing this program that plays 10 hands of Poker and outputs to the user what his hand is. The problem

I need some help in writing this program that plays 10 hands of Poker and outputs to the user what his hand is.

The problem I'm having is trying to find out how to use suitsInHand[SUITS] and facesInHand[FACES] as counters for suits and faces in a hand.

Here are the instructions:

suitsInHand is 4 counters that represents how many hearts, clubs, diamonds, spades are in the hand. These 4 counters must add up to 5. For example if you have 5 hearts in the hand of cards, the array would have the values 5,0,0,0

facesInHand is 13 counters, that represent how many twos, threes, etc. you have in the hand. This must also total 5. For example, if you have a pair of 3s, and three Kingss, this array would have the values 0,2,0,0,0,0,0,0,0,0,3,0

While dealing a hand of cards, keep a count of the suitsInHand, and facesInHand.

This is my code so far:

#include  #include  #include  #define SUITS 4 // suits of cards #define FACES 13 // two - ace #define AVAILABLE 0 // card not drawn from deck #define TAKEN 1 // card has been drawn from deck #define SIZE 5 #define TRUE 1 #define FALSE 0 void dealACard(char *suits[], char *faces[], int deck[][FACES]); void dealAHand(char *suits[], char *faces[], int deck[][FACES]); void analyzeHand(int suitsInHand[], int facesInHand[]); //igrone this for now typedef int bool; bool straight, flush, four, three; int pairs; /* can be 0, 1, or 2 */ main(){ char *suits[4] = {"Hearts", "Diamonds", "Spades", "Clubs"}; char *faces[13] = {"Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace" }; int deck[4][13] = { AVAILABLE }; // using array to make sure the same card is drawn from a single deck int i; int suitsInHand[SUITS], facesInHand[FACES]; srand(time(NULL)); for(i = 0; i < 10; i++) { dealAHand(suits, faces, deck); analyzeHand(suitsInHand, facesInHand); // igrone for now } system("pause"); } void dealAHand(char *suits[], char *faces[], int deck[][FACES]){ int i; for(i = 0; i < 5; i++) dealACard(suits, faces, deck); printf(" "); } void dealACard(char *suits[], char *faces[], int deck[][FACES]){ int suitIndex, faceIndex; suitIndex = rand() % 4; faceIndex = rand() % 13; while (deck[suitIndex][faceIndex] == TAKEN){ suitIndex = rand() % 4; faceIndex = rand() % 13; } deck[suitIndex][faceIndex] = TAKEN; printf("%s of %s ", faces[faceIndex], suits[suitIndex]); } /* analyzeHand: Determines whether the hand contains a straight, a flush, four-of-a-kind, and/or a three-of-a-kind; determines the number of pairs; stores the results into the external variables straight, flush, four, three, and pairs. */ void analyzeHand(int suitsInHand[], int facesInHand[]){ int num_consec = 0; int rank, suit; straight = FALSE; flush = FALSE; four = FALSE; three = FALSE; pairs = 0; /* check for flush */ for (suit = 0; suit < SUITS; suit++) if (suitsInHand[suit] == 5) flush = TRUE; /* check for straight */ rank = 0; while (facesInHand[rank] == 0) rank++; for (; rank < FACES && facesInHand[rank]; rank++) num_consec++; if (num_consec == 5) { straight = TRUE; return; } /* check for 4-of-a-kind, 3-of-a-kind, and pairs */ for (rank = 0; rank < FACES; rank++) { if (facesInHand[rank] == 4) four = TRUE; if (facesInHand[rank] == 3) three = TRUE; if (facesInHand[rank] == 2) pairs++; } if (straight && flush) printf("Straight flush "); else if (four) printf("Four of a kind "); else if (three && pairs == 1) printf("Full house "); else if (flush) printf("Flush "); else if (straight) printf("Straight "); else if (three) printf("Three of a kind "); else if (pairs == 2) printf("Two pairs "); else if (pairs == 1) printf("Pair "); else printf("High card "); } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!