// double f_temp, c_temp, k_temp; // we don't need these globals
// return void if we don't have anything meaningful to return
void print_temperatures( double f_temp ) {
// static: these constants can be reused over and over again
// (just good style; in practice, doesn't make a difference because the compiler knows it too.)
// perhaps, give somewhat more meaningful names for this constants.
staticconstdouble c1 = 5 / 9.0 ;
staticconstdouble c2 = 32;
staticconstdouble c3 = 273.16; // should be 273.15 iirc
// in contrast, the constants c_temp and k_temp are not static
// they are freshly recomputed each time the function is called
constdouble c_temp = (f_temp-c2) * c1;
constdouble k_temp = c_temp + c3 ;
if( k_temp >= 0 ) // sanity check: not below absolute zero
// https://en.wikipedia.org/wiki/Absolute_zero
{
printf("The original temperature is %.2f degrees Fahrenheit. \n\n ", f_temp);
printf("This temperature in Celsius is %.2f degrees Celsius. \n\n ", c_temp);
printf("This temperature in Kelvin is %.2f Kelvin. \n\n ", k_temp);
}
else printf( "invalid temperature: %.2f degrees Fahrenheit is below absolute zero.\n\n ", f_temp );
}