# Help please/ need help

0 votes
asked Oct 8, 2018

Start by writing a program that converts Celsius temperatures to Fahrenheit temperatures. The formula is F = (9/5)C + 32 where F is the Fahrenheit temperature and C is the Celsius temperature. Enhance the program by allowing the user to choose between converting from Celsius to Fahrenheit and vice versa. See the below output. You will need to look up the formula for the other directions (simply google it!). Allow for both upper and lower-case menu item selections and generate an appropriate error message if the user enters something unexpected. Format your output to always show one decimal. You will build on this assignment in future chapters.

The output should look something like this:
Enter c (or C) to convert Fahrenheit to Celsius
or f (or F) to convert Celsius to Fahrenheit: c

Enter the temperature: 0.0
0.0 Celsius is 32.0 degrees Fahrenheit.

Running the program again:
Enter c (or C) to convert Fahrenheit to Celsius
or f (or F) to convert Celsius to Fahrenheit: F

Enter the temperature: 212
212.0 Fahrenheit is 100.0 degrees Celsius.

## 1 Answer

0 votes
answered Oct 11, 2018 by (540 points)
edited Oct 11, 2018 by Lukas
#include <stdio.h>

int main()

{
float temperature;
char which;

printf("Enter f to convert Fahrenheit to Celsiusor or c to convert Celsius to Fahrenheit: ");
scanf("%c",&which);

if (which == 'c')
{
printf("\nCelsius: ");
scanf("%f",&temperature);
printf("\n%.1f Grad Celsius correspond", temperature);
printf(" %.1f Grad Fahrenheit.\a\n",temperature*9/5+32);

} else if (which == 'f')
{
printf("\Fahrenheit: ");
scanf("%f",&temperature);
printf("\n%.1f Grad Fahrenheit correspond", temperature);
printf(" %.1f Grad Celsius.\a\n",(temperature-32)*9/5);

}
else
printf("\n\aWrong input!\nPlease restart the program");

return(0);
}