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

(Romina) #1

printf("Three of a kind\n\n");
return (3);
}
else if (pairs == 2) {
printf("Two pairs\n\n");
return (2);
}
else if (pairs == 1) {
printf("Pair\n\n");
return (1);
}
else {
printf("High Card\n\n");
return (0);
}
}


// This function looks through each of the five cards in the first hand
// and asks the user if they want to keep the card. If they say no,
// they get a replacement card.


void getFinalHand(int cardRank[], int cardSuit[], int finalRank[],
int finalSuit[], int ranksinHand[],
int suitsinHand[])
{
int i, j, cardDup;
char suit, rank, ans;


for (i=0; i < 5; i++)
{
suit = getSuit(cardSuit[i]);
rank = getRank(cardRank[i]);
printf("Do you want to keep card #%d: %c%c?", i+1, rank, suit);
printf("\nPlease answer (Y/N): ");
scanf(" %c", &ans);
if (toupper(ans) == 'Y')
{
finalRank[i] = cardRank[i];
finalSuit[i] = cardSuit[i];
ranksinHand[finalRank[i]]++;
suitsinHand[finalSuit[i]]++;
continue;
}
else if (toupper(ans) == 'N')
{
cardDup = 0;
do {
cardDup = 0;
finalRank[i] = (rand() % 13);
finalSuit[i] = (rand() % 4);


// First check your new card against the 5 original
// cards to avoid duplication
for (j=0; j < 5; j++)
{
if ((finalRank[i] == cardRank[j]) &&
(finalSuit[i] == cardSuit[j]))
{

Free download pdf