Question: Perform temperature conversion in an ask-before-iterating loop (Chapter 4 Practice Program 3): Repeat Chapter 3 Practice Program 5 that allows a user to convert temperatures.
Perform temperature conversion in an ask-before-iterating loop (Chapter 4 Practice Program 3):
Repeat Chapter 3 Practice Program 5 that allows a user to convert temperatures. In an outer loop, prompt for a (double) temperature value and then prompt for C/c or F/f for the type of temperature, Celsius or Fahrenheit, using Scanner method next(); if they enter something else, loop until they enter one of those values (a nested inner validation loop!), but do not ask them to repeat entering the temperature value.
Once you know the type, use if/else or switch statements to convert it to the other type and print the result, using these formulas:
C = 5*(F - 32) / 9 and F = (9*C/5) + 32
After printing the converted output, ask the user to type Q/q to quit, or to press any other key to repeat the outer loop and perform another conversion (its OK to use break; to end the outer loop if they type Q/q).
Part of the output from your program should look like this if the user entered 100 C Q:
100.0 degrees C = 212.0 degrees F.
Enter 'Q' to quit or any other character
to perform another temperature conversion.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
