So we have to make this slot machine esc program, input how much you bet, spin, and ask to repeat. It compiles fine but when I have the part that asks for a bet it like kills the choice to play again.
Here is my code now and the part with problem here is the part that when I remove it, it allows me to replay. So help on where I went wrong would be great. thanks.
Code
public class SlotMachine
{
public static void main(String[] args)
{
Random rand = new Random();
Scanner keyboard = new Scanner (System.in);
DecimalFormat cash = new DecimalFormat("#0.00");
double bet = 1, winnings;
int slot1, slot2, slot3;
String replay = "y";
do
{
System.out.print("How much would you like to bet?"); //problem
bet = keyboard.nextDouble(); //here
while(bet<0.01)
{
System.out.print("You must bet at least a penny, re enter a bet.");
bet = keyboard.nextDouble();
}
slot1 = rand.nextInt(5);
if (slot1 == 0)
System.out.print("Cherries ");
else if (slot1 == 1)
System.out.print("Oranges ");
else if (slot1 == 2)
System.out.print("Plums ");
else if (slot1 == 3)
System.out.print("Bells ");
else if (slot1 == 4)
System.out.print("Melons ");
else if (slot1 == 5)
System.out.print("Bars ");
slot2 = rand.nextInt(5);
if (slot2 == 0)
System.out.print("Cherries ");
else if (slot2 == 1)
System.out.print("Oranges ");
else if (slot2 == 2)
System.out.print("Plums ");
else if (slot2 == 3)
System.out.print("Bells ");
else if (slot2 == 4)
System.out.print("Melons ");
else if (slot2 == 5)
System.out.print("Bars ");
slot3 = rand.nextInt(5);
if (slot3 == 0)
System.out.println("Cherries ");
else if (slot3 == 1)
System.out.println("Oranges ");
else if (slot3 == 2)
System.out.println("Plums ");
else if (slot3 == 3)
System.out.println("Bells ");
else if (slot3 == 4)
System.out.println("Melons ");
else if (slot3 == 5)
System.out.println("Bars ");
if (slot1 == slot2 && slot1 == slot3)
{
winnings = bet * 3;
System.out.println("You won $" + winnings);
}
else if (slot1 == slot2 || slot1 == slot3 || slot2 == slot3)
{
winnings = bet * 2;
System.out.println("You won $" + winnings);
}
else
System.out.println("You won $0.");
System.out.print("roll again?");
replay = keyboard.nextLine();
}while(replay.equalsIgnoreCase("y"));
}
}
This post was edited by J-dawg on Nov 5 2014 03:55pm