-
Conversion Query
Hey, I'm having trouble with this program. I'm trying to convert degrees F to degrees C with the conversion factor. But when I execute the program, degrees C always comes out to 0. Anyone have an idea as to what I'm doing wrong? Here's the program...
Code:
#include <iostream>
using namespace std;
int main ()
{
int F, C;
cout << "Enter temperature in Fahrenheit: " << flush;
cin >> F;
cout << endl;
static_cast<int>(C = (5/9)*(F - 32));
cout << "Current temperature = " << F << "F" << endl;
cout << "Current temperature = " << C << "C" << endl;
return 0;
}
-
your error: 5/9 is an integer devision. the result is 0
use 5.0 / 9.0 instead
edit:
uh...
you probably want:
C = static_cast<int>( 5.0 / 9.0 ... )
-