lundi 2 mars 2015

BlackJack If Statements - Java

I have instances where if statements occur at the same time and give two outputs when it should truly only have one real answer. Below is the code that it runs through and the console output of which if statements print which are labeled. This happens on multiple other occasions.



if(playertotal>21)
{
System.out.println("You bust, you lose!");
}
if((playertotal<dealertotal)&&(playertotal==21));
{
System.out.println("You Win!(1)");
money=wager+money;
}
if(playertotal==dealertotal)
{
System.out.println("You've Tied!");
}
if((playertotal>dealertotal)&&(playertotal<=21))
{
System.out.println("You Win!(2)");
money=wager+money;
}
if((playertotal<dealertotal)&&(dealertotal<=21))
{
System.out.println("You Lose!");
money=money-wager;
}
if((playertotal>21)&&(dealertotal>21))
{
System.out.println("You've both busted!");
}

System.out.println("The dealer has "+dealertotal);
System.out.println("You now have $"+money);


Console output; Welcome to Game of 21! You have $2000. What is your wager? 10 You have 20 Hit? (Y/N) N You Win!(1) You Win!(2) The dealer has 17 You now have $2020


Aucun commentaire:

Enregistrer un commentaire