I apologize, I am new to C programming. I know my current program will not compile. Can anyone give me insight into what I can do to fix it? Specifically, how can I store the the start temperature so it can be used again in the final printf statement "start degrees Fahrenheit is converted Celsius."?
Note - I want to use the float data type for precision.
Code:
//THIS PROGRAM WILL CONVERT TEMPERATURES BETWEEN DEGREES FAHRENHEIT AND DEGREES CELSIUS
#include <stdio.h>
int main(void)
{
//DECLARE VARIABLES
char x;
float start_temp, end_temp;
//DISPLAY TO USER THE PURPOSE OF THE PROGRAM
printf ("\n\n");
printf ("This program will convert temperatures between degrees Fahrenheit and degrees Celsius.");
printf ("\n\n");
//ASK WHICH SYSTEM USER WOULD LIKE TO CONVERT
printf ("Would you like to convert from Fahrenheit or Celsius (Enter C or F): ");
scanf ("%c", &x);
printf ("\n");
//IF FAHRENHEIT; ENTER TEMPERATURE
if (x == 'F' || x == 'f')
{
printf ("Enter the temperature in Fahrenheit (F): ");
scanf ("%f", &start_temp);
end_temp = (start_temp-32)/1.8;
//DISPLAY RESULT
printf ("%f degrees Fahrenheit is %f Celsius.", start_temp, end_temp);
}
//IF CELSIUS; ENTER TEMPERATURE
else
{
printf ("Enter the temperature in Celsius (C): ");
scanf ("%f", &start_temp);
end_temp = start_temp * 1.8 + 32;
//DISPLAY RESULT
printf ("%f degrees Celsius is %f Fahrenheit.", start_temp, end_temp);
}
printf ("\n\n");
//END PROGRAM
return 0;
}