Points:         25

Due:               At 11:59 PM on the designated day

PURPOSE:

1.                   Selection control structures; if, if-else; multiple alternative

2.                   Good programming style

a.       Reasonable comments/documentation

b.       Good variable names

c.       Whitespace & indentation

PROGRAM:

You will write a program that will compute the value of a hand of three playing cards. The hands will be one of the possible hands listed in the table at right. 

Text Box: Hand
Illegal Input(Bad Hand)
One Pair
Three of a Kind
Straight
Flush
Straight Flush
Royal Straight Flush

This is similar to 5 card poker, but two pairs, a full house (three of one kind and a pair of another) and four of a kind are no longer possible.

 

A card is represented by an integer.  0 is to be an ace and thus the other aces in the deck, which is represented by the integers 0 to 51, are 13, 26 and 39.  The kings are numbered 12, 25, 38 and 51.  It is assumed that there is only one deck of cards. A hand will be generated using a random number generator. In your program,  to generate a hand randomly, use the statements in the box at right. You must include <stdlib.h> and <cmath> in your program to make the random functions and time functions, respectively, available.

 

Note that the illegal input result of the Three Card Hand is caused by two or more cards having the same value.

Text Box: srand((unsigned) time(NULL));

card1 = rand()%52;
card2 = rand()%52;
card3 = rand()%52;
ALGORITHM

There are two key tests that must be performed frequently… (use cut and paste…)

  1. Are two cards of the same suit? // uses int division
  2. Are two cards of the same rank? // uses int modulus division

The previous two questions must be answered (possibly multiple times) for each of the following:

    1. Illegal Input

                                                               i.      Making sure there are no duplicates

    1. Is it three of a kind (ALL THE SAME RANK)

                                                          i.      Test1 3 times

    1. Is it a pair (TWO ARE THE SAME RANK, BUT NOT ALL THREE)

                                                          i.      Test1 3 times

    1. Is it a flush (ALL OF THE SAME SUIT)

                                                          i.      Test2 3 times

    1. Is it Straight (THREE CONSECUTIVE RANK, CAN BE DIFFERENT SUITS)

....     etc;

Your program should get three cards by inputting them, gets the result of the hand and prints the hand and its result.

Recommended design:

Check for, in order, illegal input, three of a kind, pair, straight flush (and if so, is it royal?), flush, straight. Ace can be high or low, that is, Ace-Two-Three and Queen-King-Ace are both straights.

 

Turnin:

Your project, named project2.cpp  (all lower case). 2 point penalty for non-compliance.