//摄氏度与华氏度的转换
#include <iostream>
#include<iomanip>
using namespace std;
float c,f; //c为摄氏度,
int select; //选择功能变量,1为摄氏度转华氏度,2为华氏度转摄氏度
char character; //是否继续接收Y或N的变量
//主函数
int main()
{
float transform1(float); //摄氏度转华氏度(计算)
float transform2(float); //华氏度转摄氏度(计算)
void Celsius_to_Fahrenheit(); //转换函数1(摄氏度转华氏度,调用计算函数后输出结果)
void Fahrenheit_to_Celsius(); //转换函数2(华氏度转摄氏度,调用计算函数后输出结果)
while(1)
{ cout<<endl;
cout<<"\t\t\t ≯华氏——摄氏温标转换器≮"<<endl<<endl;
cout<<"\t\t\t ********************"<<endl;
cout<<"\t\t\t * 1.摄氏度转华氏度 *"<<endl;
cout<<"\t\t\t * 2.华氏度转摄氏度 *"<<endl;
cout<<"\t\t\t * 3.退出 *"<<endl;
cout<<"\t\t\t ********************"<<endl<<endl;
cout<<"\t\t\t 请选择:";
cin>>select;
system("cls");
switch(int(select))
{
case 1:Celsius_to_Fahrenheit();
break;
case 2:Fahrenheit_to_Celsius();
break;
case 3:system("cls");
cout<<"程序作者:**"<<endl;
cout<<"学号:209*******"<<endl;
cout<<"班级:计算机***班"<<endl;
cout<<"电话:138********/6*****"<<endl;
cout<<"QQ:67*******"<<endl;
system("pause");
exit(0);
default:cout<<endl<<"\t\t\t 你的输入有误,请重新输入!";
}
}
cin.get();
return 0;
}
float transform1(float) //计算摄氏度
{
c=5.0/9*(f-32);
return c;
}
float transform2(float) //计算华氏度
{
f=(9.0/5)*c+32;
return f;
}
void Celsius_to_Fahrenheit(void) //摄氏度转华氏度
{
while(1)
{
cout<<endl<<"\t\t\t ﹦摄氏度转华氏度﹦"<<endl;
cout<<"\t\t\t 请输入一个摄氏温度:";
cin>>c;
cout<<"\t\t\t 华氏度:"<<setprecision(3)<<transform2(c)<<endl;
cout<<"\t\t\t 是否继续?(Y/N):";
cin>>character;
system("cls");
if(character=='Y'||character=='y')
continue;
else if(character=='N')break;
else cout<<endl<<"\t\t\t 你的输入有误,请重输:";
}
}
void Fahrenheit_to_Celsius(void) //华氏度转摄氏度
{
while(1)
{
cout<<endl<<"\t\t\t ﹦华氏度转摄氏度﹦"<<endl;
cout<<"\t\t\t 请输入一个华氏温度:";
cin>>f;
cout<<"\t\t\t 摄氏度:"<<setprecision(3)<<transform1(f)<<endl;
cout<<"\t\t\t 是否继续?(Y/N):";
cin>>character;
system("cls");
if(character=='Y'||character=='y')
continue;
else if(character=='N')break;
else cout<<endl<<"\t\t\t 你的输入有误,请重输:";
}
}
//本程序还有一个错误等更正,就是在主界面时如果输入字母或其它符号,会死循环。
加载中,请稍候......