Poker Game Trouble

My is suppose to output these examples:
Here are example results:
AH
QH
TH
8H
4H
The rank of the hand is: Flush
TS
5H
5S
5D
5C
The rank of the hand is: Four of Kind
JH
TC
7S
6S
5S
The rank of the hand is: Nothing
TS
9H
8D
7S
6C
The rank of the hand is: Straight
JH
9S
8H
8D
3C
The rank of the hand is: One Pair

I included the different types of ranks in the program (Flush, One Pair, etc.) but when I enter the example imputes above I don't get those outputs. Any advice on how to fix the code?

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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include <iostream>
#include <ctime>
using namespace std;

void dealHand(char R[], char S[], int n);
void inputHand(char R[], char S[], int n);
bool straightFlush(char R[], char s[], int n);
bool flush(char R[], char s[], int n); //done 
bool fullHouse(char R[], char s[], int n);
bool threeKind(char R[], char s[], int n);
bool straight(char R[], char s[], int n); //done
bool fourKind(char R[], char s[], int n); //done 
bool twoPair(char R[], char s[], int n); //done
bool onepair(char R[], char s[], int n); //done



int main(void){
	const int N = 5;
	char Rank[N], Suit[N];
	int i;

	// Call srand() just once, at the beginning of main() 
	srand((unsigned int)time(NULL));

	// inputHand prompts the user for a hand
	// CAREFUL: enter rank in descending order
	// The ranks, i.e. T or 9, sent back in Rank
	// The suits, i.e. C or H, sent back in Suit

	cout << "User inputs a hand:" << endl;	// LINE 22
	inputHand(Rank, Suit, N);       			// LINE 23

	//cout << "Call dealHand():" << endl;	// LINE 25
	//dealHand(Rank, Suit, N);  		    // LINE 26
	// dealHand generates a random hand of N cards
	// Each hand is from a fresh deck of 52 playing cards
	// The ranks, i.e. T or 9, sent back in Rank
	// The suits, i.e. C or H, sent back in Suit

	cout << endl;
	for (i = 0; i < N; i++)
		cout << Rank[i] << Suit[i] << endl;
	cout << endl;

	if (straightFlush(Rank, Suit, N) == true)
		cout << "Straight Flush!" << endl;
	else if (flush(Rank, Suit, N))
		cout << "Flush!" << endl;
	else if (straight(Rank, Suit, N))
		cout << "Straight!" << endl;
	else if (twoPair(Rank, Suit, N))
		cout << "Two Pair!" << endl;
	return 0;

}
void dealHand(char R[], char S[], int n){
	int i, j, cnum, cards[52], temp[52];
	string ranks = "23456789TJQKA";
	string suits = "CDHS";

	if (n > 52){
		cout << "Error...cannot deal " << n
			<< " cards from a 52-card deck\n";
		return;
	}
	for (i = 0; i < 52; i++)
		cards[i] = i;

	for (i = 0; i<500; i++)
		swap(cards[rand() % 52], cards[rand() % 52]);

	for (i = 0; i < n; i++){
		temp[i] = cards[51 - i];
	}
	for (i = 0; i < n - 1; i++)
		for (j = i + 1; j < n; j++)
			if (((temp[i] % 13) < (temp[j] % 13))
				|| (((temp[i] % 13) == (temp[j] % 13)) && ((temp[i] / 13) < (temp[j] / 13))))
				swap(temp[i], temp[j]);

	for (i = 0; i < n; i++){
		cnum = temp[i];
		R[i] = ranks[cnum % 13];
		S[i] = suits[cnum / 13];
	}

}
void inputHand(char R[], char S[], int n){
	int i;
	cout << "Input a hand of " << n << " cards in rank order" << endl;
	for (i = 0; i < n; i++)
	{
		cout << "input rank[" << i << "] ";
		cin >> R[i];  R[i] = toupper(R[i]);
		cout << "input suit[" << i << "] ";
		cin >> S[i];  S[i] = toupper(S[i]);
	}
}
bool flush(char R[], char s[], int n){

	if (s[0] == s[1] == s[2] == s[3] == s[4]){
		return true;
	}
	else{
		return false;
	}
}
bool straight(char R[], char s[], int n){

	int arrayi[5];
	for (int j = 0; j < 5; j++){

		if (R[j] == 't'){
			arrayi[j] == 10;
		}
		else if (R[j] == 'j'){
			arrayi[j] == 11;
		}
		else if (R[j] == 'q'){
			arrayi[j] == 12;
		}
		else if (R[j] == 'k'){
			arrayi[j] == 13;
		}
		else if (R[j] == 'a'){
			arrayi[j] == 14;
		}
		else
			arrayi[j] == R[j];


	}

	if ((arrayi[0] == (arrayi[1] - 1)) && (arrayi[0] == (arrayi[2] - 2)) && (arrayi[0] == (arrayi[3] - 3)) && (arrayi[0] == (arrayi[4] - 4))){

		return true;

	}
	else
		return false;


}


bool fourKind(char R[], char s[], int n){

	if (((R[0] == R[1]) && (R[0] == R[2]) && (R[0] == R[3]) || (R[1] == R[2]) && (R[1] == R[3]) && (R[1] == R[4]))){
		return true;
	}
	else
		return false;


}

bool threeKind(char R[], char s[], int n){

	for (int i = 2; i < 5; i++){
		if (R[i] == R[i - 1] && R[i] == R[i - 2])
			return true;
	}
	return false;
}
bool twoPair(char R[], char s[], int n){
	int pairs = 0;
	for (int i = 0; i <= 3; i++){

		if (R[i] == R[i + 1])
			pairs++;

	}
	if (pairs == 2)
		return true;
	else
		return false;


}
bool straightFlush(char R[], char s[], int n){

	if (straight(R, s, n) && flush(R, s, n))
		return true;
	else
		return false;

}
bool onepair(char R[], char s[], int n){

	if (((R[0] == R[1]) || (R[1] == R[2]) || (R[2] == R[3]) || (R[3] == R[4])))
		return true;
	else
		return false;

}


Just a quick perusal, but in line s 95 and 97 you convert everything to upper case, but in lines 114 - 126 you are comparing things to lower case.
Line 102 doesn't do what you think it does. It should be
if (s[0] == s[1] and s[0] == s[2] and s[0] == s[3] and s[0] == s[4]) {
Lines 115, 118, etc: == should be =

Your code for checking most hands assumes that the hand is sorted by rank, but I'm not sure if this is always true. Also, an ace can participate in two straights: A2345 or TJQKA. In other words it can be ranked either 1 or 14, so you may need some special code for the case of of A2345.

Instead of saying
1
2
3
4
if (stuff)
    return true;
else
    return false;
you can say simply
return stuff;
A disadvantage of this method is that it can make it hard to see what the return value is in a debugger, so I often change the code slightly to:
1
2
bool result = stuff;
return result;


Topic archived. No new replies allowed.