C++ Poker: skipping over If statements, and disregarding values -
i have been creating poker in c++, , noticed after have determined (or thought) player's hands, shows royal flush (or 9, in terms of hand_ranking). tested , came out if statements determining hands being skipped over. why these statements not registering, , how can fixed? p.s. know code kind of long, if don't feel looking @ please carry on.
int hand_ranking = 0; bool one_pair_bool; int one_pair; bool two_pair_bool; int two1_pair; int two2_pair; if (min_all == min2_all){ one_pair = min_all; one_pair_bool = true; if (mid_card == max2_all){ two_pair_bool = true; two1_pair = min_all; two2_pair = mid_card; } else if (max2_all == max_all){ two_pair_bool = true; two1_pair = min_all; two2_pair = max2_all; } else{ two_pair_bool = false; } } else if (min2_all == mid_card){ one_pair = min2_all; one_pair_bool = true; if (max2_all == max_all){ two_pair_bool = true; two1_pair = min2_all; two2_pair = max2_all; } else { two_pair_bool = false; } } else if (mid_card == max2_all){ one_pair = mid_card; one_pair_bool = true; if (min_all == min2_all){ two_pair_bool = true; two1_pair = mid_card; two2_pair = min_all; } else{ two_pair_bool = false; } } else if (max2_all == max_all){ one_pair = max2_all; one_pair_bool = true; if (min_all == min2_all){ two_pair_bool = true; two1_pair = max2_all; two2_pair = min_all; } else if (min2_all == mid_card){ two_pair_bool = true; two1_pair = max2_all; two2_pair = min2_all; } else{ two_pair_bool = false; } } else{ one_pair_bool = false; } bool three_of_a_kind; int three_of_a_kind_number; if (min_all == min2_all && min2_all == mid_card){ three_of_a_kind = true; three_of_a_kind_number = min_all; } else if (min2_all == mid_card && mid_card == max2_all){ three_of_a_kind = true; three_of_a_kind_number = min2_all; } else if (mid_card == max2_all && max2_all == max_all){ three_of_a_kind = true; three_of_a_kind_number = mid_card; } else { three_of_a_kind = false; } bool straight; int straight_start; if (min_all == min2_all - 1 && min2_all == mid_card - 1 && mid_card == max2_all - 1 && max2_all == max_all - 1){ straight = true; straight_start = min_all; } else { straight = false; } bool flush; char flush_suit; if (min_suit == min2_suit == mid_suit == max2_suit == max_suit){ flush = true; flush_suit = min_suit; } bool full_house; int full_house2; int full_house3; if (min_all == min2_all && min2_all == mid_card){ if (max2_all == max_all){ full_house = true; full_house2 = max2_all; full_house3 = min_all; } } else if (min2_all == mid_card && mid_card == max2_all){ } else if (mid_card == max2_all && max2_all == max_all){ if (min_all == min2_all){ full_house = true; full_house2 = min_all; full_house3 = mid_card; } } else { } bool four_of_a_kind; int four_of_a_kind_number; if (min_all == min2_all - 1 && min2_all == mid_card - 1 && mid_card == max2_all - 1){ four_of_a_kind = true; four_of_a_kind_number = min_all; } else if (min2_all == mid_card - 1 && mid_card == max2_all - 1 && max2_all == max_all - 1){ four_of_a_kind = true; four_of_a_kind_number = min2_all; } bool straight_flush; char straight_flush_suit; int straight_flush_start; if (min_all == min2_all - 1 && min2_all == mid_card - 1 && mid_card == max2_all - 1 && max2_all == max_all - 1 && min_suit == min2_suit && min2_suit == mid_suit && mid_suit == max2_suit && max2_suit == max_suit){ straight_flush = true; straight_flush_start = min_all; straight_flush_suit = min_suit; } else { straight_flush = false; } bool royal_flush = false; char royal_flush_suit; if (min_all == 1 && min2_all == 10 && mid_card == 11 && max2_all == 12 && max_all == 13 && min_suit == min2_suit && min2_suit == mid_suit && mid_suit == max2_suit && max2_suit == max_suit){ royal_flush = true; royal_flush_suit = min_suit; } else{ royal_flush = false; } if (royal_flush = true){ hand_ranking = 9; } else if (straight_flush == true){ hand_ranking = 8; } else if (four_of_a_kind == true){ hand_ranking = 7; } else if (full_house == true){ hand_ranking = 6; } else if (flush == true){ hand_ranking = 5; } else if (straight == true){ hand_ranking = 4; } else if (three_of_a_kind == true){ hand_ranking = 3; } else if (two_pair_bool == true){ hand_ranking = 2; } else if (one_pair == true){ hand_ranking = 1; } else{}
it looks you're assigning instead of comparing:
if (royal_flush = true){ hand_ranking = 9; }
that line sets royal_flush
true
, evaluates true, set hand_ranking
9.
i assume want royal_flush == true
inside if statement, compares 2 values. if(true == royal_flush)
way write compiler catch these types of errors. , if(royal_flush)
work well.