Everything compiles fine but it does not identify a straight. It will find straight flush though. A hand consists of 5 objects of the class CARDS which has 3 int variables(Value, Suit, Position). When I send a straight through it it goes all the way through to else and returns "Error!" I cannot figure out why please help me out. I went over the code many times but nothing stands out, it may just need a fresh set of eyes. If it is too confusing to figure out quickly tell me and I will add comments to explain everything.
string GetHandName(HAND5 hand){
bool Sorting = true;
CARD Move;
string HandName;
//sort from smallest to biggest
while (Sorting){
if (hand.Card[0].Value > hand.Card[1].Value){
Move = hand.Card[0];
hand.Card[0] = hand.Card[1];
hand.Card[1] = Move;
}
else if (hand.Card[1].Value > hand.Card[2].Value){
Move = hand.Card[1];
hand.Card[1] = hand.Card[2];
hand.Card[2] = Move;
}
else if (hand.Card[2].Value > hand.Card[3].Value){
Move = hand.Card[2];
hand.Card[2] = hand.Card[3];
hand.Card[3] = Move;
}
else if (hand.Card[3].Value > hand.Card[4].Value){
Move = hand.Card[3];
hand.Card[3] = hand.Card[4];
hand.Card[4] = Move;
}
else{Sorting = false;}
}
//check for straight flush and 5 high exception (A,2,3,4,5)
if (hand.Card[0].Value == hand.Card[1].Value - 1 &&
hand.Card[1].Value == hand.Card[2].Value - 1 &&
hand.Card[2].Value == hand.Card[3].Value - 1 &&
hand.Card[3].Value == hand.Card[4].Value - 1){
if (hand.Card[0].Suit == hand.Card[1].Suit &&
hand.Card[0].Suit == hand.Card[2].Suit &&
hand.Card[0].Suit == hand.Card[3].Suit &&
hand.Card[0].Suit == hand.Card[4].Suit){
if (hand.Card[4].Value == 13){HandName = "Royal Flush!!";}
else {
HandName = "Straight Flush, ";
HandName = HandName + GetCardValueL(hand.Card[4]);
HandName.append(" High");
return HandName;
}
}
}
else if (hand.Card[0].Value == hand.Card[1].Value - 1 &&
hand.Card[1].Value == hand.Card[2].Value - 1 &&
hand.Card[2].Value == hand.Card[3].Value - 1 &&
hand.Card[4].Value == Ace){
if (hand.Card[0].Suit == hand.Card[1].Suit &&
hand.Card[0].Suit == hand.Card[2].Suit &&
hand.Card[0].Suit == hand.Card[3].Suit &&
hand.Card[0].Suit == hand.Card[4].Suit){
HandName = "Straight Flush, ";
HandName = HandName + GetCardValueL(hand.Card[5]);
HandName.append(" High");
return HandName;
}
}
//check for four of a kind
else if ((hand.Card[0].Value == hand.Card[1].Value &&
hand.Card[0].Value == hand.Card[2].Value &&
hand.Card[0].Value == hand.Card[3].Value) ||
(hand.Card[1].Value == hand.Card[2].Value &&
hand.Card[1].Value == hand.Card[3].Value &&
hand.Card[1].Value == hand.Card[4].Value)){
HandName = "Four of a Kind, ";
HandName = HandName + GetCardValueL(hand.Card[3]);
HandName.append("'s");
return HandName;
}
//check for full house
else if (hand.Card[0].Value == hand.Card[1].Value &&
hand.Card[2].Value == hand.Card[3].Value &&
hand.Card[2].Value == hand.Card[4].Value){
HandName = "Full House, ";
HandName = HandName + GetCardValueL(hand.Card[2]);
HandName.append("'s Full of ");
HandName = HandName + GetCardValueL(hand.Card[0]);
HandName.append("'s");
return HandName;
}
else if (hand.Card[0].Value == hand.Card[1].Value &&
hand.Card[0].Value == hand.Card[2].Value &&
hand.Card[3].Value == hand.Card[4].Value){
HandName = "Full House, ";
HandName = HandName + GetCardValueL(hand.Card[0]);
HandName.append("'s Full of ");
HandName = HandName + GetCardValueL(hand.Card[3]);
HandName.append("'s");
return HandName;
}
//check for flush
else if (hand.Card[0].Suit == hand.Card[1].Suit &&
hand.Card[0].Suit == hand.Card[2].Suit &&
hand.Card[0].Suit == hand.Card[3].Suit &&
hand.Card[0].Suit == hand.Card[4].Suit){
HandName = "Flush, ";
HandName = HandName + GetCardValueL(hand.Card[4]);
HandName.append(" High");
return HandName;
}
//check for straight and 5 high exception (A,2,3,4,5)
else if (hand.Card[0].Value == hand.Card[1].Value - 1 &&
hand.Card[1].Value == hand.Card[2].Value - 1 &&
hand.Card[2].Value == hand.Card[3].Value - 1 &&
hand.Card[3].Value == hand.Card[4].Value - 1){
HandName = "Straight, ";
HandName = HandName + GetCardValueL(hand.Card[4]);
HandName.append(" High");
return HandName;
}
else if (hand.Card[0].Value == hand.Card[1].Value - 1 &&
hand.Card[1].Value == hand.Card[2].Value - 1 &&
hand.Card[2].Value == hand.Card[3].Value - 1 &&
hand.Card[4].Value == Ace){HandName = "Straight, Five High"; return HandName;}
//check for three of a kind
else if ((hand.Card[0].Value == hand.Card[1].Value &&
hand.Card[0].Value == hand.Card[2].Value) ||
(hand.Card[1].Value == hand.Card[2].Value &&
hand.Card[1].Value == hand.Card[3].Value) ||
(hand.Card[2].Value == hand.Card[3].Value &&
hand.Card[2].Value == hand.Card[4].Value)){
HandName = "Three of a Kind, ";
HandName = HandName + GetCardValueL(hand.Card[2]);
HandName.append("'s");
return HandName;
}
//check for two pair
else if ((hand.Card[0].Value == hand.Card[1].Value &&
hand.Card[2].Value == hand.Card[3].Value) ||
(hand.Card[0].Value == hand.Card[1].Value &&
hand.Card[3].Value == hand.Card[4].Value)){
HandName = "Two Pair, ";
HandName = HandName + GetCardValueL(hand.Card[3]);
HandName.append("'s and ");
HandName = HandName + GetCardValueL(hand.Card[0]);
HandName.append("'s");
return HandName;
}
else if (hand.Card[1].Value == hand.Card[2].Value &&
hand.Card[3].Value == hand.Card[4].Value){
HandName = "Two Pair, ";
HandName = HandName + GetCardValueL(hand.Card[4]);
HandName.append("'s and ");
HandName = HandName + GetCardValueL(hand.Card[1]);
HandName.append("'s");
return HandName;
}
//check for pair
else if (hand.Card[0].Value == hand.Card[1].Value ||
hand.Card[1].Value == hand.Card[2].Value){
HandName = "Pair of ";
HandName = HandName + GetCardValueL(hand.Card[1]);
HandName.append("'s");
}
else if (hand.Card[2].Value == hand.Card[3].Value ||
hand.Card[3].Value == hand.Card[4].Value){
HandName = "Pair of ";
HandName = HandName + GetCardValueL(hand.Card[3]);
HandName.append("'s");
}
else {
HandName = GetCardValueL(hand.Card[4]);
HandName.append(" ");
HandName = HandName + GetCardValueL(hand.Card[3]);
HandName.append(" High");
return HandName;
}
return "Error!";
}