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

(Romina) #1

void printGreeting();
int getBet();
char getSuit(int suit);
char getRank(int rank);
void getFirstHand(int cardRank[], int cardSuit[]);
void getFinalHand(int cardRank[], int cardSuit[], int finalRank[],
int finalSuit[], int ranksinHand[],
int suitsinHand[]);
int analyzeHand(int ranksinHand[], int suitsinHand[]);


main()
{
int bet;
int bank = 100;
int i;
int cardRank[5]; // Will be one of 13 values (Ace-King)
int cardSuit[5]; // Will be one of 4 values (for Clubs, Diamonds,
// Hearts, Spades)
int finalRank[5];
int finalSuit[5];
int ranksinHand[13]; // Used for evaluating the final hand
int suitsinHand[4]; // Used for evaluating the final hand
int winnings;
time_t t;
char suit, rank, stillPlay;


// This function is called outside the do...while loop because
// the greeting
// only needs to be displayed once, while everything else in main
// will run
// multiple times, depending on how many times the user wants to
// play.


printGreeting();


// Loop runs each time the user plays a hand of draw poker


do {
bet = getBet();


srand(time(&t));
getFirstHand(cardRank, cardSuit);
printf("Your five cards: \n");
for (i = 0; i < 5; i++)
{
suit = getSuit(cardSuit[i]);
rank = getRank(cardRank[i]);
printf("Card #%d: %c%c\n", i+1, rank, suit);
}


// These two arrays are used to figure out the value of
// the player's hand. However, they must be zeroed out
// in case the user plays multiple hands.


for (i=0; i < 4; i++)
{

Free download pdf