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();

twc = windChill(tAir,wSpeed);

Edited by happygeek: fixed formatting

8 Years
Discussion Span
Last Post by GDICommander

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



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:

while (//The variables have their correct value);
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.