473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Poker Program

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
7 13237
Banfa
9,065 Expert Mod 8TB
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
D_C
293 100+
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
9,065 Expert Mod 8TB
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
You can also create poker with Actionscript
Aug 21 '07 #5
kreagan
153 100+
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
104 100+
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
9,065 Expert Mod 8TB
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

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

Similar topics

22
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html ...
1
by: Martin Olsen | last post by:
Hi all. I am creating a program which calculates poker odds. The program should look at the visible cards (those on your hand and those on the table) then count the cards needed to improve the...
27
by: Simon Biber | last post by:
I was reading http://en.wikipedia.org/wiki/Poker_probability which has a good description of how to count the frequency of different types of poker hands using a mathematical approach. A sample...
4
by: hardieca | last post by:
Has anyone heard of an open-source .NET engine that calculates the winning and losing percentages of hands? Regards, Chris
15
by: sandy123456 | last post by:
At the moment im trying to write a hand class for a game poker patientnce But when i get to the part having to catergorise the difference of full house straight flush flush four of a kind and...
13
by: kinghippo423 | last post by:
Hello Everyone, I did a poker program in Java that essencially finds the strenght of a poker hand created Randomly. My program is doing OK...but I'm pretty sure it can be optimised. This is my...
24
by: bnashenas1984 | last post by:
Hi every one I'm trying to make a little poker game but I don't know how to evaluate the strength of a 7 card hand.. It's not that hard with 5 cards. Actually I found some program to do that with...
9
by: teejayem | last post by:
I am looking for some help! I am currently developing a new game for an online community. The game is called Pokino which ishalf bingo and half poker. Wierd eh?! Anyway... The final part...
7
by: Extremity | last post by:
Hi, I am taking a intro to C++ course so my knowledge base only limits to areas such as if/else, functions, and recursions. We are creating a program which will determine the probability of Poker...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.