import java.util.Scanner; // For user input

/**
* Compute wind chill given temp. in Fahrenheit and wind speed in miles per hour
* Ref.: J. Adams et al., C++: An Intro. to Computing
*
* @author (Michael Branicky)  09/10/2007
*/

// Modification of WindChill3.java to use a while sentinel

public class WindChillWhile {
   public static void main(String args[]) {
      // Declaration of variables to be used
      double windSpeed, tempFahr, vPart, windChill;
  
      // Create Scanner to obtain input from command window
      Scanner input = new Scanner( System.in );

      // NEW: INITIALIZATION
      windSpeed = 0.0;

      // NEW: while loop, indentation
      while (windSpeed != -1.0) {
         // Get user input
         System.out.print("Enter temp. (F): ");
         tempFahr = input.nextDouble();
         System.out.print("Enter wind speed (mph; -1 to end): ");
         windSpeed = input.nextDouble();

         if ((windSpeed < 4.0) || (tempFahr > 50.)) {
            if (windSpeed < 4.0) {
               System.out.println("ERROR: windspeed must be >= 4 mph");
            }
  
            if (tempFahr > 50.0) {
               System.out.println("ERROR: temperature must be <= 50 F");
            }
         }
         else {
            // compute v_part
            vPart = 0.474677 - 0.020425 * windSpeed + 0.303107 * Math.sqrt(windSpeed);

            // compute wind chill
            windChill = 91.4 - vPart * (91.4 - tempFahr);

            // Display output
            System.out.println("Wind Chill index = " + windChill);
         }
      }
   }
}
