# Thread: Conversion from Fahrenheit to Celsius problem

1. ## Conversion from Fahrenheit to Celsius problem

I'm doing a simple code which converts an entered amount of degrees Fahrenheit to Celsius. I'm running sample test data and there appears to be a converting problem.

Code:
```//This program will convert a temperature of Fahrenheit  to Celsius
#include <iostream>
using namespace std;

//Function Prototypes
int Celsius(int);

int main()
{
int F, // # of degrees Fahrenheit
C; // # of degrees Celsius

cout <<"This program will convert a temperature of Fahrenheit to Celsius." << endl;
cout <<"Please enter the amount of degrees (integer) Fahrenheit." << endl;
cin  >> F;
C = Celsius(F);
cout << F << " degrees Fahrenheit converted to Celsius is " << C << endl;

system("pause");
return 0;
}
//************************************************
//Definition of function Celsius.                *
//This function converts Fahrenheit to Celsius.  *
//************************************************
int Celsius(int F)
{

return ((5 / 9) * (F - 32)); // Formula used to convert Fahrenheit to Celsius

}```
My first test data was 32 and it came out correctly with a conversion of 0 degrees Celsius. When I tried one (1), it gave me an output of zero (0) as with others numbers I have entered. Can you help me identify the problem?

Edit:
I know some answers will come out with a decimal, but I'm only concerned with "whole" numbers.

2. 5/9 is always 0
5.0/9.0 is better.

3. Originally Posted by Salem
5/9 is always 0
5.0/9.0 is better.
Since you say dividing 5.0 and 9.0 is better than 5 and 9, would it be better if I change the function Celsius to double? In example, instead of int Celsius (int), it would be double Celsius (double).

4. Yes, probably.

The thing with math with integers only is that the results can only be integers.

5. If you're only worried about outputting whole numbers, it's ok to leave the result as an int, as long as all of the calculations are done as doubles. Changing to 5.0/9.0 accomplishes that already, so I don't think it's necessary to change the function to use doubles unless you want the output to include decimals.

6. If you write (F - 32) * 5 / 9, that will give the correct result, and avoid unnecessary convention to and from double. The key is that multiplication is done first.

The only issue that arises is that both my suggestion, and converting to and from double, will always round the result down. This can be adjusted by adding the following modifier: (int)( (F - 32) * 5 &#37;9 > 4 ).

Alternatively, you can have the function take and return doubles, and use 32.0, 5.0, and 9.0 as constants