I really need some help implementing counters. I have to count the suits and faces drawn from the deck but for some reason all outputs is junk numbers. Am I missing something? I what it to come out something like this:
Say a player is dealt:
Ace of Hearts
Ten of Clubs
Ace of Clubs
Eight of Hearts
Seven of Diamonds
2 2 1 0 // see this one counts the 2 hearts drawn, the 2 clubs, etc.
0 0 0 0 0 1 1 0 1 0 0 0 2
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SUITS 4
#define FACES 13
#define AVAILABLE 0
#define TAKEN 1
void dealACard(int suitsInHand[], int facesInHand[],char *suits[], char *faces[], int deck[][FACES]);
void dealAHand(int suitsInHand[], int facesInHand[], char *suits[], char *faces[], int deck[][FACES]);
//void analyzeHand();
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;
int suitsInHand[4];
int facesInHand[13];
int suitsInHand2[4];
int facesInHand2[13];
srand(time(NULL));
dealAHand(suitsInHand, facesInHand, suits, faces, deck);
dealAHand(suitsInHand2, facesInHand2, suits, faces, deck);
system("pause");
}
void dealAHand(int suitsInHand[], int facesInHand[], char *suits[], char *faces[], int deck[][FACES]){
int i;
for(i = 0; i < 5; i++)
dealACard(suitsInHand, facesInHand, suits, faces, deck);
printf("\n");
}
void dealACard(int suitsInHand[], int facesInHand[], 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;
/* Here are the counters but all it outputs is junk. Do I need a for loop?*/
facesInHand[faceIndex]++;
suitsInHand[suitIndex]++;
printf("%s of %s \n", faces[faceIndex], suits[suitIndex]);
}
Any suggestions will be much appreciated. If my question still seems a bit hazy, I will be happy to clarify some more. Thanks for any help :)