18Temperature Converter

You’ll often need to determine which part of a program is run based on user input or other events.

Create a program that converts temperatures from Fahrenheit to Celsius or from Celsius to Fahrenheit. Prompt for the starting temperature. The program should prompt for the type of conversion and then perform the conversion.

The formulas are

images/_pragprog/svg-0006.png

and

images/_pragprog/svg-0007.png

Example Output

 
Press C to convert from Fahrenheit to Celsius.
 
Press F to convert from Celsius to Fahrenheit.
 
Your choice: C
 
 
Please enter the temperature in Fahrenheit: 32
 
The temperature ...

Get Exercises for Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.