I'm working on a simple blackjack game in c#
For example I have int playerTotal
and int dealerTotal
I want to compare them for which is closest to 21 and which one is greater than 21.
How can I do that?
Under proper blackjack rules, it is not sufficient to simply compare the hands. You have to do things in the proper order, which is:
You have to do it in this order or you get the wrong result. The major source of house edge in blackjack is the fact that if both you and the dealer bust, you lose, because you busted first.
"Atlantic City" rules are a bit different, in that the dealer does not have a hole card and doesn't peek. If the dealer ends up having a natural, payouts are adjusted to be as if it had been done in the way outlined above.
You can use
Math.Abs
method to find the absolute difference between those numbers and 21 then compare them:To find the greatest: