# Thread: Function help

1. ## Function help

My output for the variable celsius is 0 everytime. I can't figure it out =(. Can anyone spot what is wrong?

Code:
```#include <iostream>
using namespace std;

double get_celsius(double);

int main()
{
double fahrenheit, celsius;

cout << "This progam converts fahrenheit to celsius.\nPlease input a fahrenheit temperature...\n";
cin >> fahrenheit;

celsius = get_celsius(fahrenheit);

cout << fahrenheit << " fahrenheit is " << celsius << " celsius.\n";
return 0;
}

double get_celsius(double fahrenheit)
{
return (5/9)*(fahrenheit-32);
}```

2. Hint: with integer division, 5/9=0

3. Ok, i just put .5555 instead of 5/9, how would you code 5/9 to work?

Code:
```double get_celsius(double fahrenheit)
{
double x = 5/9,
result;

result = (fahrenheit - 32) * x;
return result;```
would that work?

4. how would you code 5/9 to work?
An easy way is to write 5.0/9.0 instead.

5. Hint:
5 == treated as an integer
5.0 == treated as a double
5.0f == treated as a float

Popular pages Recent additions