### Fractions Evaluating to 0

I'm writing a simple program to convert temperatures from Fahrenheit to Celsius and Celsius to Fahrenheit, and I've found that my fractions are evaluating to 0 and 1 even though they are double variables and the function return types are double. Is there something I'm missing? Thanks.

#include <iostream>
#include <iomanip>
using namespace std;

double fahrenheit_to_celsius (double input);
double celcius_to_fahrenheit (double input);

int main (void) {

double input_temp; //temperature to be converted
char ch; //variable to choose what conversion to run
char contin = 'y';

do {
cout << "Type 'c' to convert to Celsius or 'f' to convert to Fahrenheit: ";
cin >> ch;
cout << "\n\nEnter the temperature: ";
cin >> input_temp;

switch (ch) {
case 'c':
case 'C':
cout << "\n" << input_temp << " degrees Fahrenheit in degrees Celsius is " << fahrenheit_to_celsius (input_temp)
<< "\nDo another conversion? (y/n) ";
cin >> contin;
break;
case 'f':
case 'F':
cout << "\n" << input_temp << " degrees Celsious in degrees Fahrenheit is " << celcius_to_fahrenheit (input_temp)
<< "\nDo another conversion? (y/n) ";
cin >> contin;
break;
default:
cout << "\nError: Invalid input.\nTry again? (y/n) ";
cin >> contin;
break;
}
} while (contin == 'y' || contin == 'Y');

return 0;
}

double fahrenheit_to_celsius(double input) {

return (input - 32) * (5 / 9);
}
double celcius_to_fahrenheit(double input) {

return input * (9/5) + 32;
}

`return (input - 32) * (5 / 9);`

Look here. 5/9 = 0 because its integer division. Same with the other one. You want 5.0/9 or 5.0/9.0.
Topic archived. No new replies allowed.