473,545 Members | 937 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Poker Program

1 New Member
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 13255
Banfa
9,065 Recognized Expert Moderator Expert
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 Contributor
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 Recognized Expert Moderator Expert
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
Thorion85
1 New Member
You can also create poker with Actionscript
Aug 21 '07 #5
kreagan
153 New Member
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 New Member
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 Recognized Expert Moderator Expert
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
3580
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 Newsgroup Readers: If you circulate copies of this report to groups of computer programmers at different universities etc. around the world then they might...
1
4466
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 hand(eg. how many cards do I need to get a Flush) and then calculate the odds based on those numbers. My problem is that I do not know how I should...
27
5575
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 Python program is given in the discussion page for doing it that way. I wanted to take a different approach and actually generate all the possible...
4
8893
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
6451
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 straight i got stuck.I need to write boolean methods to return these (stright flush , four of a kind..etc) I can only do a pair and 2 pairs and three of a...
13
2533
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 results with 1 million hands: Number of hands generated : 1000000 Straight Flush : 0.0012 % In theory : 0.0012%
24
7040
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 5 cards but the problem is that there is 5 flop cards and 2 cards that the player has in hand. I don't even know how to start that .... (identify...
9
4680
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 of the program needs to evaluate two 5 card poker hands and determine which one out of the two hands wins. I thought rather than create a new class...
7
5655
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 Hands, such as Royal Flush, Straight Flush, Four of a Kind and such. However in order to complete this, I need to determine how many different poker...
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7419
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7756
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5326
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1879
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.