Enter a temperature in Fahrenheit and request the output in Celsius. The formula is
Keep to two decimal places
Sample input
-40.00
Sample output
-40.00
This question is very simple, just plug the data into the formula. Remember to set the floating point type of double or float--"for retaining two decimal places.
For decimals:
1 is that you can use iomanip's cout<< fixed << setprecision (2) <<C<<endl;, 2 is that you can use printf("%.2f",C) in C language; f specifically represents floating point type For data, ".2" means keeping two decimal places
#include<iostream>
#include<iomanip> //专门保留小数的头文件
using namespace std;
//温度转换
int main() {
double F, C;
cin >> F;
C = 5 / 9.0 * (F - 32);
cout << fixed <<setprecision(2) << C << endl;
//printf("%.2f",C);
return 0;
}