Poker game help

I'm trying to write a function to count how many suits are dealt out in a hand and to do this for each hand separately for an assignment.

The assignment:

make an arrays: int suitsInMyHand[4]

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 a hand of 5 cards. For example if you have 5 hearts in the hand of cards, the array would have the values 5 0 0 0

This is my total code so far for dealing out the hands of cards but the bottom function is where i am stuck.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 #include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define SUITS 4
#define FACES 13
#define AVAILABLE 0
#define TAKEN 1


void dealACard(char *suits[], char *faces[], int deck[][FACES]);
void dealAHand(char *suits[], char *faces[], int deck[][FACES]);
void cardsInHand(char *suits[]);

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 };
	int i;

	srand(time(NULL));

	for (i = 0; i < 4; i++)
		dealAHand(suits, faces, deck);

	system("pause");
}

void dealAHand(char *suits[], char *faces[], int deck[][FACES])    {
	int i;

	for (i = 0; i < 5; i++)
		dealACard(suits, faces, deck);
	printf("\n");
}

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 \n", faces[faceIndex], suits[suitIndex]);

}

void cardsInHand(char *suits[])	{
	int suitsInMyHand[4];
	int i;

	for (i = 0; i < 5; i++)	{
		
	}


}
Revised code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define SUITS 4
#define FACES 13
#define AVAILABLE 0
#define TAKEN 1


void dealACard(char *suits[], char *faces[], int deck[][FACES]);
void dealAHand(char *suits[], char *faces[], int deck[][FACES]);
void cardsInHand(char *suits[]);

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 };
	int i;

	srand(time(NULL));

	for (i = 0; i < 1; i++)
		dealAHand(suits, faces, deck);

	system("pause");
}

void dealAHand(char *suits[], char *faces[], int deck[][FACES])    {
	int i;

	for (i = 0; i < 5; i++)
		dealACard(suits, faces, deck);
	for (i = 0; i < 5; i++)
		cardsInHand(suits);
	printf("\n");
}

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 \n", faces[faceIndex], suits[suitIndex]);

}

void cardsInHand(char *suits[])	{
	int suitsInMyHand[4];

		if (suits[SUITS] = suits[0])	{
			suitsInMyHand[0]++;
		}
		else if (suits[SUITS] = suits[1])	{
			suitsInMyHand[1]++;
		}
		else if (suits[SUITS] = suits[2])	{
			suitsInMyHand[2]++;
		}
		else if (suits[SUITS] = suits[3])	{
			suitsInMyHand[3]++;
		}
	}
does anyone have any ideas
Have you learned structures yet?

Since you're not returning any values from your functions how do you know what card was dealt in the dealAHand() function?

Also you may want to consider const qualifying some of the variables your passing to and from your functions. For example:

void dealACard(cons char *suits[], const char *faces[], int deck[][FACES]);

What is the purpose of deck[][]?
We have not learned structures yet and the purpose of the deck[][] is so that the same card is not dealt twice. I pretty much need to know how to use suitIndex number from dealACard function to be able to count them in cardsInMyHand function.
Topic archived. No new replies allowed.