Hi guys,
I'm trying to develop a card program, which seems to be working fine, with the exception of the dealing part.
The deck is initialised, shuffled, then is supposed to deal out 5 cards without duplicates. However I keep seeing duplicates when I deal. I've ran though it countless times but I can't see how the duplicates are getting through. Can anyone shed any light?
void deal()
{
char suits[4] = {0,1,2,3};
char faces[13] = {'A','2','3','4','5','6','7','8','9','X','J','Q','K'};
int deck[52];
int i, j, k, card, suit, face;
int hand[5];
srand(time(0));
for (i=0;i<5;i++)
{
j = rand()%52;
card = deck[j];
for (k=0;k<5;k++)
{
if (card == hand[k])
{
i--;
break;
}
else
{
hand[i] = card;
suit = card/13;
face = card%13;
printf ("%c of %c \n", faces[face], suits[suit]+3);
break;
}
}
}
}