I am a student of software development and I need to convert from Fahrenheit to Celsius but my code calculates it wrong. Here is my code:
int main() {
// configure the out put to display money
cout.setf(ios::fixed); //no scientific notation
cout.setf(ios::showpoint); //show decimal point
cout.precision(0); //two decimal for cents
int fahrenheit = 0 ;
int celsius = 5/9*(fahrenheit-32);
cout << "Please enter Fahrenheit degrees: ";
cin >> fahrenheit ;
cout << "Celsius: " << celsius << endl;
return 0;
}
If you have to use int, then you should perform division as last step to reduce loss of precision for int-types. But keep in mind, that this may cause int-overflows (shouldn't be a problem for temperatures...)