fahrenheit to celsius program

I am not getting the desired output.

1
2
3
4
5
6
7
int main(){
	int tempInF;
	cout << "Enter temp in fahr: ";
	cin >> tempInF;
	int celsius = (tempInF - 32) * (5 / 9);
	cout << celsius;
}
I guess I'm supposed to make the 5 or 9 a 5.0 or 9.0. Beats me.
closed account (2AoiNwbp)
You are probably getting a zero, if so, that`s because you're doing integer division, thus, 5/9 truncates results to 0. And (tempInF - 32) times 0 is zero.
Let's change your formula to 5 * (tempInF - 32) / 9 and give a try.

regards,
Alejandro
Last edited on
Thanks
Topic archived. No new replies allowed.