I have to make a program that generates 2 random numbers and awards money if certain numbers come out (2 of the same = 3.00, 2 even numbers that aren't the same will give 50 cents, and 2 different numbers gets nothing).
I have the main code done but I cannot make it loop to ask for the next part.
Basically I need it to run once, update the times variable (meaning you've played X amount of times. and also I need the Amount won to change).
I cannot make it loop and update those values.
I think I need a return somewhere but I don't know how to implement it with a for loop.
here is the code:
By the way this gives an infinite loop. My other version has a System.exit(0) in it which terminates it after one go, but I only need it to terminate if the user inputs 'N' for no. Other then that it'll keep running and asking for the users input until he/she says no.import java.util.Scanner; import java.io.*; import java.text.NumberFormat; // // // // // public class RollEE { public static void main(String[]args) { Scanner keyboard = new Scanner (System.in); double balance = 10.00; int randomNumber; int randomNumber2; int randomNumberSum; int counter; int times = 0; double amountLost = 0; System.out.println("*** Welcome to the RollEE program **"); System.out.println("A play costs 1 dollar. If you roll equal numbers, you win 3 dollars."); System.out.println("If you roll even, you win 50 cents. If you roll odd, you do not win anything."); System.out.print("Do you want to play? Type (Y/N): "); String response = keyboard.nextLine(); randomNumber = (int)(Math.random( ) * 6)+1; randomNumber2 = (int)(Math.random( ) * 6)+1; while (response.equals("y") || response.equals("Y")) { System.out.println("Thank you for your bet. A bet of $1 has been placed."); NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(2); nf.setMaximumFractionDigits(2); if (randomNumber == randomNumber2) { System.out.println("You rolled " + randomNumber + ", " + randomNumber2 + ". " + "For this play you won $3.00"); balance = balance + 2.00; times = times++; System.out.println("Your new balance is: $" + nf.format(balance)); } randomNumberSum = randomNumber + randomNumber2; if (randomNumberSum%2 == 1) { System.out.println("You rolled " + randomNumber + ", " + randomNumber2 + ". " + "For this play you won $0.00"); balance = balance - 1.00; times = times++; System.out.println("Your new balance is: $" + nf.format(balance)); } if ((randomNumber != randomNumber2) && (randomNumberSum%2 != 1 )) { System.out.println("You rolled " + randomNumber + ", " + randomNumber2 + ". " + "For this play you won $.50"); balance = balance - 0.50; amountLost = -0.50; times = times++; System.out.println("Your new balance is: $" + nf.format(balance)); } } double amountLost2 = Math.abs(amountLost); while ((response.equals("n") || response.equals("N")) && (amountLost < 0)) { System.out.println("You played " + times + " times. You lost $" + amountLost2); System.exit(0); } } }