Hi everyone,
I'm trying to write a program that deals a 5 card poker hand and determines whether or not there is a pair and/or a flush. I have an array hand[] that the cards are dealt into and came up with his loop to see if there is a pair and/or flush. I realized after the first loop it will start comparing values in array positions that don't exist...I know there must be a simpler way of writing this, but I can't figure it out.
Thanks for any help!Code:..... for (int k = 0; k <= 4; k++) { if ((hand[k].getValue() == hand[k+1].getValue()) || (hand[k].getValue() == hand[k+2].getValue()) || (hand[k].getValue() == hand[k+3].getValue()) || (hand[k].getValue() == hand[k+4].getValue())) pair ++; if ((hand[k].getSuit() == hand[k+1].getSuit()) && (hand[k].getSuit() == hand[k+2].getSuit()) && (hand[k].getSuit() == hand[k+3].getSuit()) && (hand[k].getSuit() == hand[k+4].getSuit())) flush ++; } .....
-Ryan