Jun 13, 2013 at 7:34pm UTC
I've written a simple code to covert Fahrenheit to Celsius, however no matter what input you put in, you ALWAYS get an output of 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#include <iostream>
using namespace std;
float tempConv(float );
int main()
{
float fTemp, cTemp;
cout << "Enter the Fahrenheit temperature" << endl;
cin >> fTemp;
cTemp = tempConv(fTemp);
cout << "The celcius temperature is " << cTemp << endl;
return 0;
}
float tempConv(float tFTemp)
{
float tCTemp;
tCTemp = (5/9) * (tFTemp - 32);
return tCTemp;
}
When debugging putting 100 for Fahrenheit will transfer over to the function, and even into the equation, however the tCTemp variable always is set to 0 after tCTemp = (5/9) * (tFTemp - 32);
Last edited on Jun 13, 2013 at 7:34pm UTC
Jun 13, 2013 at 7:47pm UTC
The problem is the division 5/9
. Both numbers are integers so it will do integer division and give the result 0 which makes the whole thing 0.
Jun 13, 2013 at 8:06pm UTC
Yup that worked. Thanks.
stupid integer division.