this has been driving me nuts!! I am trying to ask the user of my little game to enter a bet that is divisble by .25 and if they input an number that is not i want a JOptionPane input box to appear and ask the user it input a number that is divisible by .25 However, if the user inputs a number that is divisible the game needs to move on the the game. My problem is when I input a number in the first place that is not divisible it moves on to the input box asking to put in a number that is divisble, but when I enter a number that is divisble instead of moving onto the game like I want it to it just goes back to the first JOptionPane box. This is driving me crazy I dont know what Im doing wrong.
import javax.swing.JOptionPane;
import java.util.Random;
public class Project3_practice
{
public static void main (String [] args)
{
Random questions = new Random();
int s1, s2, s3 = 0;
double number = 0.0;
String input;
double winnings = 0;
double balance = 0;
do
{
input = JOptionPane.showInputDialog("Welcome to Jay's Slot Machine \n\nPlace your bet");
number = Double.parseDouble(input);
number = number*100;
if(number%25!=0)
input = JOptionPane.showInputDialog("Please Enter an amount divisible by $.25");
else
}while(number%25 != 0);
input = JOptionPane.showInputDialog("Do you want to play \nIt costs $.25 per play", "yes or no");
while(input.equals("yes")){
//game code
//updateBalance(s1,s2,s3);
input = JOptionPane.showInputDialog("Do you want to play again?");
}
}
public static double updateBalance(int a, int b, int c)
{
return 2.5;
}
}
loop helptrying to use an if statement with a do/while loop
Page 1 of 1
1 Replies - 1170 Views - Last Post: 24 March 2007 - 04:52 PM
Replies To: loop help
#2
Re: loop help
Posted 24 March 2007 - 04:52 PM
Well just some quick things, in the first if statement you have an else clause, and you never set the number variable again, so when it hits the while in the do-while loop it's looking at the number from before, which you already checked with the if statement.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|