By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,133 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

Poker Program

P: 1
I just started programming in C, and I need some help with this problem.

Your program will read the information about one MiniPoker hand, namely the rank and suit of the hand’s
first card, and the rank and suit of its second card. Note that the two cards in a hand may be entered in
any order; it’s not necessarily the case that the highest card will appear first, for example. Your program will
then determine whether the hand is valid, and classify the hand as to what type it is.
Your program should first print a message asking its user to enter the necessary input data, and should
then read four pieces of information from the input. The information to be read is specifically as follows:
1
1. The first piece of information to be read from the input is an integer which should represent the rank
of the first card in the hand:
• The numbers 2 through 10 indicate that indicates the first card is a two through a ten, respectively.
• The number 11 indicates that indicates the first card is a jack.
• The number 12 indicates that indicates the first card is a queen.
• The number 13 indicates that indicates the first card is a king.
• The number 14 indicates that indicates the first card is an ace.
2. The second piece of information to be read from the input is a single letter which should indicate the
suit of the first card in the hand:
• An uppercase C indicates the first card is a club.
• An uppercase D indicates the first card is a diamond.
• An uppercase H indicates the first card is a heart.
• An uppercase S indicates the first card is a spade.
3. The third piece of information to be read from the input is an integer which should represent the rank
of the second card in the hand, which follows the same rules as that of the rank of the first card above.
4. The fourth piece of information to be read from the input is a letter which should represent the suit of
the second card in the hand, which follows the same rules as that of the suit of the first card above.
These four data items will always be separated from each other by at least one whitespace character (a
blank, tab, or newline), but arbitrary additional whitespace may optionally appear before or after these input
data items, or in between them.
2.2 Program output
After analyzing the two cards forming the hand, your program should print a single output line containing
one and only one of the following phrases. The phrases for valid MiniPoker hands are listed first, before the
phrases to be printed for incorrect hands.
1. Your program should print a line containing one of the exact phrases “two high”, “three high”,
“four high”, “five high”, “six high”, “seven high”, “eight high”, “nine high”, “ten high”,
“jack high”, “queen high”, “king high”, or “ace high”, indicating the rank of the highest card in
the hand, if the hand doesn’t fall into any of the categories below. Note that this is the lowest type of
card hand.
2. Your program should print a line containing one of the exact phrases “pair of twos”, “pair
of threes”, “pair of fours”, “pair of fives”, “pair of sixes”, “pair of sevens”, “pair
of eights”, “pair of nines”, “pair of tens”, “pair of jacks”, “pair of queens”, “pair of
kings”, or “pair of aces”, depending upon the cards’ ranks, if the two cards in the pair have the
same rank. (The cards’ suits don’t matter, except that they should not be identical, otherwise the hand
would be of a a different type described below.) This is the second–lowest type of card hand.
3. Your program should print a line containing the exact phrase “straight” if the two cards in the pair
form a (simple) straight, meaning that their ranks have adjacent value, but their suits aren’t the same.
For example, a hand with a four of clubs and a five of diamonds is a straight, as is a hand with a queen
of diamonds and a king of hearts.
4. Your program should print a line containing the exact word “flush” if the two cards in the pair form
a flush. A hand is a (simple) flush when the two cards’ suits are the same, but their ranks are not the
same and also don’t have adjacent values, and they are not royalty. (Note that if the two cards’ suits
were the same and their ranks were the same or had adjacent values, or the cards were royalty, the hand
would be one of the three special flush types below.)
2
5. Your program should print a line containing the exact phrase “straight flush” if the two cards in the
pair form a straight flush, which is a flush in which the two cards’ ranks also have adjacent values (the
cards form both a straight as well as a flush).
6. Your program should print a line containing the exact phrase “royal flush” if the two cards in the
pair form a flush in which both cards are royalty.
7. Your program should print a line containing the exact phrase “royal straight flush” if the two cards
in the pair form a flush in which the two cards’ ranks have adjacent values and both cards are royalty.
Note that this is the highest type of card hand.
Although there is some overlap in the conditions describing the hand types, your program must identify
the most specific or highest type of hand represented by two cards. For example, if the hand read consisted
of an eight of spades and a nine of spades, they form a straight, as well as a flush, as well as a straight flush,
so since a straight flush is the highest of these three hand types that is considered the type of this hand.
Note also that since the conditions overlap, the words in the phrases above also do to some extent, but the
messages your program prints must categorize each hand type exactly, and not also describe any other hand
type. For example, if the hand read consisted of a five of diamonds and a ten of diamonds, the description
above says “your program should print a line containing the exact word ‘flush’ ”, but the message printed
must contain only the word “flush”, not the phrases “straight flush”, “royal flush”, or “royal straight flush”.
Note that as the syllabus discusses, your program can print additional information on the output lines
(for example, see the sample output section below), as long as they contain the required words or phrases.
The phrases to be printed if your program detects that the poker hand is incorrect are:
1. Your program should print a line containing the exact phrase “first card is invalid” if the first
card is incorrect in any way (i.e., either its rank or suit is incorrect).
2. Your program should print a line containing the exact phrase “second card is invalid” if the second
card is incorrect in any way.
3. Your program should print a line containing the exact phrase “cards are identical” if the two cards
are the same. Since a deck of cards doesn’t have any duplicates, something is wrong if a MiniPoker
hand contains two of the same cards.
If any input line contains more than one of the errors described, your program can print any one (and
only one) of the error phrases, at your option
Oct 17 '06 #1
Share this Question
Share on Google+
7 Replies


Banfa
Expert Mod 5K+
P: 8,916
We are not doing your assignment for you. Attempt this exercise and post here with any specific problems you are having with the code.
Oct 17 '06 #2

100+
P: 293
D_C
When I did something like this in Java, I gave the cards a numeric value of 0-51. It made the comparisons for which type of hand easier. Modulo and division operations give the 2-A and suit.

Also, I think "two high" through "six high" are unnecessary. A 2 is the lowest card you can have, if that's also your highest you should have 5 two's. If you have six high, and no pairs, then you have a straight.
Oct 17 '06 #3

Banfa
Expert Mod 5K+
P: 8,916
Also, I think "two high" through "six high" are unnecessary. A 2 is the lowest card you can have, if that's also your highest you should have 5 two's. If you have six high, and no pairs, then you have a straight.
You've miss read the question, a mini poker hand (as described by the problem) only consists of 2 cards. As such the hands "two high" and "three high" are unrequired.

If you have "two high" then you must have a "pair of twos" (2,2) (as D_C mentions).

If you have "three high" then you must have either a "straight" (2,3) or a "pair of threes" (3,3). There are no other card combinations with 3 as the highest card.

You can have "four high" (4,2) as long as it isn't a "flush".
Oct 17 '06 #4

P: 1
You can also create poker with Actionscript
Aug 21 '07 #5

kreagan
100+
P: 153
We are not doing your assignment for you. Attempt this exercise and post here with any specific problems you are having with the code.
Agreed, but here is a tip to start the project. Write skeleton code to generate the process.

Dealer.C

void dealHand( int number_players);
void dealSingleCard(); //Texas hold 'em.

.....
Aug 21 '07 #6

arunmib
100+
P: 104
I just started programming in C, and I need some help with this problem.

Your program will read the information about one MiniPoker hand, namely the rank and suit of the hand’s
first card, and the rank and suit of its second card. Note that the two cards in a hand may be entered in
any order; it’s not necessarily the case that the highest card will appear first, for example.
.........................

2. Your program should print a line containing the exact phrase “second card is invalid” if the second
card is incorrect in any way.
If any input line contains more than one of the errors described, your program can print any one (and
only one) of the error phrases, at your option
Wow !! This is by far one of the good requirements/specification document I've ever got. :)
Enough kidding, just try to draw a flowchart for what you have typed. Using that try writing a pseudo-code. Then writing code would be easy. If still have problems, post here.....
Aug 22 '07 #7

Banfa
Expert Mod 5K+
P: 8,916
To everyone replying to this thread in August 2007.

Can I point out that the OP was made in October 2006, additionally the nature of the question makes me think it was coursework and finally it is the only post the poster made.

If they were looking for help with coursework then the deadline for completion has almost certainly past, and an account that has been inactive for this long is usually destined to stay inactive.

Feel free to discuss this problem amongst yourselves but please do not expect any feedback from the original poster as I suspect they have moved onto other things long ago.
Aug 22 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.