PDA

View Full Version : Convert



Xiang
Dec 29th, 2002, 11:34 AM
Dear sir,

I want to convert a temperature reading in fahrenheit degrees to celsius, but my celsius in the end always occur 0 figure. Why???

#include <stdio.h>
main()
{
int f;
float c;
printf("Farenheit: ");
scanf(%d", &f);
c = (5/9)*(f-32);
printf("%d Fahrenheit = %f Celsius \n", f, c);
return 0;
}

Thanks

Xiang

Josh Campbell
Dec 29th, 2002, 07:09 PM
5/9 will always be 0 in integer terms. You could add a decimal to them such as 5.0/9.0 or use a cast (float)5/9.