< Home

As I am currently on a pc without Ghidra I looked into another challenge without Ghidra needed and noticed the Blackjack challenge. This is an easy one. It will output a hidden message if you reach one million dollars. You could win this challenge by pure luck or you could take a look over at the source code and notice it is missing an important check during the betting phase

Solution #1 - forgot to check userinput

int betting() //Asks user amount to bet
{
 printf("\n\nEnter Bet: $");
 scanf("%d", &bet);
  
 if (bet > cash) //If player tries to bet more money than player has
 {
        printf("\nYou cannot bet more money than you have.");
        printf("\nEnter Bet: ");
        scanf("%d", &bet);
        return bet;
 }
 else return bet;
} // End Function

When entering a bet you could enter something like… say one million. Now a check happens to see if you actually have the cash to provide for your bet. If not it will re-ask you for a betting value.

What the beginner programmer forgot to do here is to actually check the second input. So now you can suddenly enter any value you want (like… 2000000) and when you win next round you will be a millionair!

The beginner programmer was better off by doing his if check and just calling the function betting() again. But everyone has his/hers beginner mistakes!

Solution #2 – negative value check

if(player_total<dealer_total) //If player's total is less than dealer's total, loss
{
   printf("\nDealer Has the Better Hand. You Lose.\n");
   loss = loss+1;
   cash = cash - bet;
   printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss);
   dealer_total=0;
   askover();
}

If you prefer to win by going bust you could also do the following, just enter a negative value of one million and hit until you go bust (or let the computer win because higher value). The code that handles your loss will just subtract the user input and no where is checked if bet is negative. So when you lose the money your bet will be added to your cash.

< Home