![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
华氏摄氏的转换-- 华氏的转换有错误在哪里#if(0)
//温度单位转换器
#include <stdio.h>
int main(int argc, char *argv[])
{
float i;
printf("请输入您现在的摄氏温度 :");
scanf("%f",&i);
float y;
y= i*9/5 +32;
printf("您所对应的华氏温度是:%.2f",y);
return 0;
}
#endif
#if(1)
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
//华氏温度 = 摄氏温度 * 9.0/ 5.0 +32;
const unsigned short ADD_SUBTRACT =32;
const double RATIO =9.0/5.0 ;
//这里也可以用宏定义 该如何写呢
double tempIn,tempOut;
char typeIn,typeOut;
cout<<"请亲们以这样的【xx.x C】或者【xx.X F】格式输入一个温度:" ;
cin>>tempIn>>typeIn;
cin.ignore(100,'\n');
cout<<"\n";
switch (typeIn)
{
case 'c':
case 'C':
tempOut = tempIn* RATIO +ADD_SUBTRACT;
typeOut ='F';
typeIn='C';
break;
case 'f':
case 'F':
typeOut ='C';
typeIn='F';
tempOut = (tempIn-ADD_SUBTRACT)/RATIO;
cin.get();
default:
typeOut ='E';
break;
}
if(typeOut !='E')
{
cout<<tempIn<<typeIn
<<" = "<< tempOut
<<typeOut<<"\n\n";
}
else
{
cout<<"输入错误!"<<"\n\n";
}
cout<<"请输入任何字符结束程序!"<<"\n";
return 0;
}
#endif