So basically, when someone's bankroll gets to 0 or below 0, I want the program to end so they cannot play any longer. Here is my current code:
import java.util.*; public class Craps { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Want to play Craps? Type yes or no."); String answer = scan.next(); System.out.println("How much is your bankroll?"); double bankroll = scan.nextDouble(); while (answer.equalsIgnoreCase("yes")) { System.out.println("What is your bet?"); double betAmount = scan.nextDouble(); if (checkWin(rollDice()) == true) { bankroll = bankroll + betAmount; System.out.println("Your current bankroll is $" + bankroll); } else { bankroll = bankroll - betAmount; System.out.println("Your current bankroll is $" + bankroll); } if (bankroll <=0) { answer = "no"; } System.out.println("Play again? Type yes or no: "); answer = scan.next(); } } public static double newBank(double betAmount, double bankroll) { double newBank = bankroll - betAmount; System.out.println(newBank); return newBank; } public static int rollDice() { Random randomNum = new Random(); int x = randomNum.nextInt(6) + 1; int y = randomNum.nextInt(6) + 1; System.out.println("Dice Rolls: " + x + " and " + y); int comeoutRoll = x + y; System.out.println("Your dice add up to: " + comeoutRoll); return comeoutRoll; } public static boolean checkWin(int comeoutRoll) { int firstRoll = comeoutRoll; if (firstRoll == 7 | firstRoll == 11) { System.out.println("Woah, winner here."); return true; } if (firstRoll == 2 | firstRoll == 3 | firstRoll == 12) { System.out.println("You lost!"); return false; } while (true) { int currentRoll = rollDice(); if (currentRoll == 7) { System.out.println("You lost!"); return false; } if (currentRoll == firstRoll) { System.out.println("They match! You win!"); return true; } System.out.println("NOT QUITE - Continue rolling..."); } } }
Help would be wonderful!