I developed a simple card game in which two cards are displayed, and the user must bet on whether they will receive a card located between the two displayed cards. If the user does not want to bet, they simply decide again. The user starts at £ 100.
The game works great in most aspects, but has a huge flaw. The user can make bets more than in the balance. So, if a user has £ 100, they bet £ 105 and they win, they will have £ 205 in their balance. This is clearly bad ! And if they have 100 pounds, they bet 105 pounds and they lose, the balance remains unchanged. This is also very bad.
So I thought a simple if statement would sort this:
if (wager > balance) { winLoseLabel.Text = "You can't bet more than you have!"; } switch (betResult) { case TIE: winloseLabel.Text = "Tie. You still lose. HA!"; myRules.Balance -= wager; break; case PLAYERWINS: winloseLabel.Text = "You win. Woop-de-do.."; myRules.Balance += wager; break; case DEALERWINS: winloseLabel.Text = "You lose. Get over it."; myRules.Balance -= wager; break; }
Why is this not working? I'm pretty sure this is something very simple, but I'm pretty new to C #, so it's easy on me!
c # if-statement
New start
source share