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;
}
your formula is using int : 5/9 meaning that you are loosing some precision change the 5 to 5.0 or if you want change Celsius to float