Helps on poker program

Write a program that will operate on a deck of 52 cards. Your program will:
1. Deal them into four random hands of 5 cards each
a. The four hands need to be kept in an array for later use.
2. Sort each hand so that it shows the cards in sequence from two as the lowest
to ace as the highest.
3. Display the cards in each hand using the card face (2, 10, King, etc.) and the
suit (Spades, Hearts, etc.)
4. Display what you determined the hand to be. A ranking of poker hands is at
http://www.pagat.com/vying/pokerrank.html
a. Straight flush
b. Four of a kind
c. Full House
d. Flush
e. Straight
f. Three of a kind
g. Two pair
h. One pair
i. Highest card
5. Each time the program is run, a different set of hands is to be dealt.
BONUS: Determine which is the winning hand. A tie is possible. (25 points)

Can someone show me how to get the BONUS part and number 4


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include<iostream>



using namespace std;
#include "Cards.h"
void main(){

	Card Deck[NumCardsInDeck];
	Card Hands[4][5];
	int i, j;

	InitDeck(Deck);

	cout << "\t The deck starts " << endl;
	DisplayDeck(Deck);
	Shuffle(Deck);
	cout << "\tAfter shuffling, your Deck is" << endl;
	DisplayDeck(Deck);

	j = 0;

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

		Hands[0][i] = Deck[j];
		j++;

	}
	SortHand(Hands[1]);
	cout << "First hand is: " << endl;
	if (HighestCard(Hands[0]))
		cout << "\tHighest Card" << endl;
	if (IsTwoPair(Hands[0]))
		cout << "\tTwo pair" << endl;
	if (IsThreeOfAKind(Hands[0]))
		cout << "\tThree of a kind" << endl;

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

		DisplayCard(Hands[0][i]);

	}
	for (i = 0; i < 5; i++) {
		Hands[1][i] = Deck[j];
		j++;
	}

	SortHand(Hands[1]);
	cout << "Second hand is: " << endl;
	for (i = 0; i < 5; i++) {

		DisplayCard(Hands[1][i]);

	}
	for (i = 0; i < 5; i++) {

		Hands[2][i] = Deck[j];
		j++;
	}
	SortHand(Hands[2]);
	cout << "3rd Hand is: " << endl;
	for (i = 0; i < 5; i++) {

		DisplayCard(Hands[2][i]);

	}
	for (i = 0; i < 5; i++) {

		Hands[3][i] = Deck[j];
		j++;
	}
	SortHand(Hands[3]);
	cout << "4th Hand is: " << endl;
	for (i = 0; i < 5; i++) {

		DisplayCard(Hands[3][i]);

	}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
	

#include <iostream>

using namespace std;

#include <stdlib.h>	// for random number stuff
#include <time.h>
#include<string.h>

#include "Cards.h"

char * ValueNames [] =	{
						"Two",
						"Three",
						"Four",
						"Five",
						"Six",
						"Seven",
						"Eight",
						"Nine",
						"Ten",
						"Jack",
						"Queen",
						"King",
						"Ace"
						};

void DisplayCard (const Card & C)
	{
	cout << ValueNames [C.Value] << " of " << (char) C.Suit << endl;
	}

void DisplayDeck (const Card Deck [])
	{
	int		i;

	for (i = 0; i < 52; i++)
		DisplayCard (Deck [i]);
	}

void DisplayHand(Card Deck[]) {
	int i;
	for (i = 0; i < 5; i++)
		DisplayCard(Deck[i]);

}


void InitDeck (Card Deck [])
	{
	int		i;
	Suits	S;
	Values	V;

	srand (time (0));
	i = 0;
	for (S = Hearts; S <= Spades; S = (Suits) (S + 1))
		for (V = Two; V <= Ace; V = (Values) (V + 1))
			{
			Deck [i].Suit	= S;
			Deck [i].Value	= V;
			i++;
			}
	}

bool IsThreeOfAKind (Card Hand [])
	{
	return ((Hand [0].Value == Hand [2].Value) ||
			(Hand [1].Value == Hand [3].Value) ||
			(Hand [2].Value == Hand [4].Value));
	}

bool IsTwoPair (Card Hand [])
	{
	if (Hand [0].Value == Hand [1].Value)
			if ((Hand [2].Value == Hand [3].Value) || (Hand [3].Value == Hand [4].Value))
					return true;
				else
					return false;
		else
			if ((Hand [2].Value == Hand [3].Value) && (Hand [3].Value == Hand [4].Value))
					return true;
				else
					return false;
	}
bool HighestCard (Card Hand[])
{
	if (Hand[0].Value != Hand[1].Value && Hand[0].Value != Hand[2].Value && Hand[0].Value != Hand[3].Value
		&& Hand[0].Value != Hand[4].Value && Hand[1].Value != Hand[2].Value && Hand[1].Value != Hand[3].Value &&
		Hand[1].Value != Hand[4].Value && Hand[2].Value != Hand[3].Value && Hand[2].Value != Hand[4].Value && Hand[3].Value != Hand[4].Value)
	{
		return true;
		cout << "a HighCard " << endl;
	}
	else
		return false;
}
void Deal(Card Deck[]) {

	int i;
	int j;
	Card Temp;
	for (i = 0; i < 5; i++) {
		j = rand() % 5;
		Temp = Deck[i];
		Deck[i] = Deck[j];
		Deck[j] = Temp;
	}
}

void SortHand(Card Hand[]) {
	int i;
	int j;
	int C1;
	int C2;
	Card Temp;

	for (j = 0; j < 5; j++)
	{
		C1 = 0;
		C2 = 1;
		for (i = 0; i <= 4; i++)
		{
			if (Hand[C1].Value > Hand[C2].Value)
			{
				Temp = Hand[C1];
				Hand[C1] = Hand[C2];
				Hand[C2] = Temp;
			}
			else;

			C1++;
			C2++;
			i++;
		}
	}
	if (Hand[3].Value > Hand[4].Value)
	{
		Temp = Hand[3];
		Hand[3] = Hand[4];
		Hand[4] = Temp;
	}
	if (Hand[2].Value > Hand[3].Value)
	{
		Temp = Hand[2];
		Hand[2] = Hand[3];
		Hand[3] = Temp;
	}

	if (Hand[1].Value > Hand[2].Value)
	{
		Temp = Hand[1];
		Hand[1] = Hand[2];
		Hand[2] = Temp;
	}
	if (Hand[0].Value > Hand[1].Value)
	{
		Temp = Hand[0];
		Hand[0] = Hand[1];
		Hand[1] = Temp;
	}

}




void Shuffle (Card Deck []){
	int		i;
	int		j;
	Card	Temp;

	for (i = 0; i < 52; i++)
		{
		j			= rand () % 52;
		Temp		= Deck [i];
		Deck [i]	= Deck [j];
		Deck [j]	= Temp;
		}
	}
}




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef CARDS_H
#define CARDS_H
const int NumCardsInDeck(52);
enum Suits	{
			Hearts = 3,
			Diamonds,
			Clubs,
			Spades
			};

enum Values	{
			Two,
			Three,
			Four,
			Five,
			Six,
			Seven,
			Eight,
			Nine,
			Ten,
			Jack,
			Queen,
			King,
			Ace
			};

struct Card
	{
	Suits	Suit;
	Values	Value;
	};

//void DisplayCard	(Card);	// passing a structure will automatically be done by value if I do not use an &
void DisplayCard	(const Card &);	// using & (pass by reference) makes the program a little faster and smaller
void DisplayDeck	(const Card []);
void InitDeck		(Card []);
bool IsThreeOfAKind	(Card []);
void Shuffle		(Card []);
void SortHand		(Card[]);
bool HighestCard	(Card[]);
void Deal			(Card[]);
bool IsTwoPair		(Card[]);

#endif 
Topic archived. No new replies allowed.