Feb 11, 2019 at 8:04am Feb 11, 2019 at 8:04am UTC
Any suggestions on how to organize these bool function calls so that they will cout the best hand. For example, if a hand returns true for both a pair and a two pair, it should cout only two pair. If a hand return true for pair, three of a kind, and full house, it should cout only full house.
I am also trying to get this validation routine right for user input into an array.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
if (containsHighCard(hand)) {
cout << "High Card!" << endl;
}
if (containsPair(hand)) {
cout << "Contains pair!" << endl;
}
if (containsTwoPair(hand)) {
cout << "Two pair!" << endl;
}
if (containsThreeOfaKind(hand)) {
cout << "Three of a kind!" << endl;
}
if (containsFourOfaKind(hand)) {
cout << "Four of a kind!" << endl;
}
if (containsStraight(hand)) {
cout << "Straight!" << endl;
}
if (containsFullHouse(hand)) {
cout << "Full House!" << endl;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
cout << "Enter five numeric cards, no face cards. Use 2 - 9." << endl;
for (int count = 0; count < NUM_CARDS; count++) {
cout << "Card " << count + 1 << ": " ;
cin >> hand[count];
while (hand[count] < 2 || hand[count] > 9) {
cout << "Please enter 2 - 9." << endl;
for (int count = 0; count < NUM_CARDS; count++) {
cout << "Card " << count + 1 << ": " ;
cin >> hand[count];
}
}
}
Last edited on Feb 11, 2019 at 8:08am Feb 11, 2019 at 8:08am UTC
Feb 11, 2019 at 9:44am Feb 11, 2019 at 9:44am UTC
That makes sense.
What do you think about the second box of code for the validation routine?
Feb 11, 2019 at 10:50am Feb 11, 2019 at 10:50am UTC
Well the inner for (int count = 0; count < NUM_CARDS; count++) is just plain wrong.
It's a loop to re-enter some given hand[count], not repeat the whole process over again.