Function always returns 0
I have an issue with a program I am writing for an assignment, I have been trying to resolve it for the past 2 days. My function keeps returning 0 and I dont know why.
This is my function prototype
Code:
float farToCel ( int ); //Farhenheit to Celcius function prototype using pass by value
This code is from main where I call the function
Code:
case 2:
cout << "Enter the value in Farenheit ";
cin >> value;
a = farToCel(value);
cout << value << " Farenheit is equal to " << a << " Celcius\n" << endl;
break;
And, here is the function definition
Code:
float farToCel(int value)
{
float result;
result = ((5 / 9) * (value - 32));
return result;
}
I have even tried debugging and value is being passed to the function correctly and it still returns a 0 every time. Could someone please let me know what I'm doing wrong here?
Re: Function always returns 0
5/9 is an integer division. How many 9's in 5, answer 0. 0 * any_num = 0, therefore 0 always gets returned.
try 5.0/9.0
Re: Function always returns 0
I wanna kick myself right now, I've been struggling with this for two days and all I needed was a .0 at the end.
Thank you very much Russco