loop help

trying to use an if statement with a do/while loop

Page 1 of 1

1 Replies - 1403 Views - Last Post: 24 March 2007 - 04:52 PM Rate Topic: -----

#1 BudLight412  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 28-January 07

loop help

Posted 24 March 2007 - 01:51 PM

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;
}
}

Is This A Good Question/Topic? 0
  • +

Replies To: loop help

#2 spullen  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 356
  • Joined: 22-March 07

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1