/* * CISC102-12 * 06.06.05 * conversion.2.c * This program converts Celsius temperatures to Fahrenheit. * - modified 06.13.05 to accept user input * - modified 06.20.05 to use a function */ #include /* STOP_VALUE is the sentinel for our input loop */ #define STOP_VALUE -99 /* * Converts Fahrenheit to Celsius. * Input is the temperature in Fahrenheit. * The returned value is the temperature in Celsius. */ double convertFtoC( double fahr ) { double celsius = (5/9.0) * ( fahr - 32 ); return celsius; // alternative implementation: // return (5/9.0) * ( fahr - 32 ); } int main() { double celsius; double fahrenheit; printf("Welcome!\n"); printf("Enter a temperature in F (Enter %d to stop): ", STOP_VALUE); scanf("%lf", &fahrenheit); /* Keep prompting for user input as long as the input * is not equal to the STOP_VALUE. */ while( fahrenheit != STOP_VALUE ) { celsius = convertFtoC(fahrenheit); printf("%.2lf degrees F is %.2lf degrees C.\n", fahrenheit, celsius); printf("Enter a temperature in F (Enter %d to stop): ", STOP_VALUE); scanf("%lf", &fahrenheit); } printf("Thank you for using my program.\n"); return 0; }