Code:
#include<stdio.h>
#define CONVERSION_FACTOR (100.0 / 180.0)
double convert (double);
int main (void)
{
/* Local Definitions */
double cel;
double fah;
/* Statements */
printf("Enter the temperature in Fahrenheit: ");
scanf("%lf", &fah);
/* call function */
cel = convert(fah);
printf("Fahrenheit temperature is: %5.1lf\n", fah);
printf("Celsius temperature is: %5.1lf\n", cel);
return 0;
} /* main */
double convert(double fah)
{
return CONVERSION_FACTOR * (fah - 32);
}
Although by no means a good looking function, still this is what you want to do. In 'C' the main focus is the breaking the code up into functions that are cohesive, and can be re-used.
Ask yourself what are the 'inputs / processes / outputs' of each function.
Main:
PROMPT for temperature in Fahrenheit
CALL conversion function
DISPLAY result
END
Converstion:
CALCULATE conversion from Fahrenheit to Celcius
RETURN result