#include<iostream>
//华氏温度 = 摄氏温度 * 9.0 / 5.0 + 32
int main()
{
const unsigned short ADD_SUBTRACT = 32;
const double RATIO = 9.0 /5.0;
double tempIn, tempOut;
char typeIn, typeOut;
std::cout<<"请亲们以【xx.x C】或者【xx.x F】这样的格式输入一个温度:\n\n";
std::cin >> tempIn >> typeIn;
std::cin.ignore(100,'\n');
std::cout << "\n";
switch( typeIn )
{
case 'C':tempOut = tempIn * RATIO +ADD_SUBTRACT;typeOut = 'F'; typeIn='C';
break;
case 'F':tempOut= (tempIn -ADD_SUBTRACT) / RATIO ;typeOut ='C'; typeIn= 'F';
break;
default:
typeOut = 'E';
break;
}
if(typeOut !='E')
{
std::cout<< tempIn << typeIn<<"="<<tempOut<<typeOut<<"\n\n";
}
else
{
std::cout << "输入错误!" << "\n\n";
}
std::cout << "请输入任何字符结束程序!\n\n";
std::cin.get();
return 0;
}
C++华氏温度和摄氏温度转换
最新推荐文章于 2023-10-10 22:21:24 发布