Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Why wont this loop properly?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
bushnerd




PostPosted: Thu Feb 09, 2006 6:01 pm   Post subject: Why wont this loop properly?

I am having trouble getting this to loop properly. I want it to loop until they enter a proper time under 4.5 seconds. When I enter it, it just ends the program.

Thanks

code:
import javax.swing.*;

public class height {
       
        public static void main (String[]args) {
                double time, answer;
                String inputStr;
                inputStr = JOptionPane.showInputDialog(null, "Enter a time less then 4.5 seconds");
                time = Double.parseDouble(inputStr);
                while (time >4.5){
               
                if (time <= 4.5) {
                        answer = 100-4.9*time*time;
                        JOptionPane.showMessageDialog(null,"The height of the object is: " +answer);
                } else {
                JOptionPane.showMessageDialog(null,"please enter a valid number under 4.5");
                        }
                        }

                }
        }
Sponsor
Sponsor
Sponsor
sponsor
Hikaru79




PostPosted: Thu Feb 09, 2006 6:11 pm   Post subject: (No subject)

Look at the following two lines, as you wrote them in your program:

Java:
while (time >4.5){
     
      if (time <= 4.5) {
I'm sure you can see now what is wrong here Smile
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: