/* exercise5-8.c -- convert fahrenheit temperature to celsius and kelvin temperature */
#include <stdio.h>
void Temperatures(double f);
const float ct1 = 1.8;
const float ct2 = 32.0;
const float ct3 = 273.16;
int main(void)
{
double temp;
printf("enter a temperature: ");
scanf("%lf", &temp);
while(temp >= 0 || temp < 0 ) // there is a bug
{
Temperatures(temp);
printf("enter a temperature(q to quit): ");
scanf("%lf", &temp);
}
printf("bye.\n");
return 0;
}
void Temperatures(double f)
{
double cel, kel;
cel = ct1 * f + ct2;
kel = cel + ct3;
printf("Fahrenheit temperature: %.2f, Celsius temperature: %.2f, \
Kelvin temperature: %.2f\n", f, cel, kel);
}
/* i need to input a number, if it is a character, then quit. but there is a bug in this program, when i input a char, it did not result correctly. how to write code in while condition? thank you. */