C Programming Absolute Beginner's Guide (3rd Edition)

(Romina) #1

printf("\nFour of a Kind\t\t\t10 credits");
printf("\nStraight Flush\t\t\t20 credits");
printf("\n\nHave fun!!\n\n");
}


// Function to deal the first five cards


void getFirstHand(int cardRank[], int cardSuit[])
{
int i,j;
int cardDup;


for (i=0; i < 5; i++)
{
cardDup = 0;
do {
// Card rank is one of 13 (2-10, J, Q, K, A)
cardRank[i] = (rand() % 13);
// Card suit is one of 4
// (club, diamond, heart, spade)
cardSuit[i] = (rand() % 4);


// Loop that ensures each card is unique
for (j=0; j < i; j++)
{
if ((cardRank[i] == cardRank[j]) &&
(cardSuit[i] == cardSuit[j]))
{
cardDup = 1;
}
}
} while (cardDup == 1);
}


}


// Function that changes the suit integer value to a character
// representing the suit


char getSuit(int suit)
{
switch (suit)
{
case 0:
return('c');
case 1:
return('d');
case 2:
return('h');
case 3:
return('s');
}
}


// Function that changes the rank integer value to a character
// representing the rank


char getRank(int rank)

Free download pdf