Function is not returning the correct number

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
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.
try (5.0/9.0)
Yup that worked. Thanks.
stupid integer division.
Topic archived. No new replies allowed.