hey guys,

I have this program that calculates the wind chill temp, But I have a little problem. The air temperature tAir should be less than 10 and the wind speed wSpeed should be over 5. So I need to keep asking for a new input from the user UNTIL i get a valid number. The way I did it, it only asks them twice (repeats twice) and that's it.
How can I keep asking until get an valid value? Here is that section of the program:

 System.out.println("Please enter the air temperature");
tAir = keyboard.nextInt(); // outside temperature


if (tAir>10);
{System.out.println("Error in air temperature (too high):" + tAir);
System.out.println("Please enter the air temprature");
tAir = keyboard.nextInt(); }



System.out.println("Please enter the wind speed:");
wSpeed = keyboard.nextInt(); // wind-speed


if ( wSpeed < 5)
{ System.out.println("Error in the wind speed (too low):" +wSpeed);
System.out.println("please enter the wind speed");
wSpeed = keyboard.nextInt();
}
else
{



twc = windChill(tAir,wSpeed);

Recommended Answers

All 3 Replies

Use code tags currently it looks like a mess I doubt anyone would feel like even looking at it.
All you need to do is put your code inside:-

[code=java] // your code here

[/code]

i'm new here, not sure what you mean.
I just wanted to know how do I keep asking for an input until a valid one
(do,while loops?)

Put all the code for input into a do-while loop.

For example:

do
{
        //Input...
}
while (//The variables have their correct value);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.