|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
在第六讲中,小甲鱼两次输入温度,第一次是 浮点型→浮点型 第二次是 整形→整形。
我按照小甲鱼写的,为什么我第二次是输入整形,他还是转换成浮点型??一下是源码,醒我大家帮我改下,告诉我错在哪里?谢谢~~
//f = c x 9 / 5 + 32
#include<iostream>
void js(double tempin, char typein);
void js(int tempin, char typein);
int main()
{
double tempin;
char typein;
int tempinint;
std::cout << "输入xx.x c or xx.x f\n";
std::cin >> tempin >> typein;
std::cin.ignore (100,'\n');
std::cout <<"\n";
js( tempin, typein);
std::cout << "输入xx c or xx f\n";
std::cin >> tempinint >> typein;
std::cin.ignore (100,'\n');
std::cout <<"\n";
js( tempinint, typein);
return 0;
}
void js(double tempin, char typein)
{
const unsigned short add = 32;
const double ratio = 9.0 / 5.0 ;
double tempout;
char typeout;
switch( typein )
{
case 'c':
case 'C':
tempout = tempin * ratio + add;
typein = 'C';
typeout = 'F';
break;
case 'f':
case 'F':
tempout = (tempin - add) / ratio;
typein = 'F';
typeout = 'C';
break;
default:
typeout = 'E';
break;
}
if( typeout != 'E' )
{
std::cout << tempin << typein
<<" = " << tempout
<< typeout << "\n \n";
}
else
{
std::cout<<"输入错误";
}
std::cout <<"请重新输入任何退出";
std::cin.get();
}
void js(int tempin, char typein)
{
const unsigned short add = 32;
const double ratio = 9.0 / 5.0 ;
double tempout;
char typeout;
switch( typein )
{
case 'c':
case 'C':
tempout = tempin * ratio + add;
typein = 'C';
typeout = 'F';
break;
case 'f':
case 'F':
tempout = (tempin - add) / ratio;
typein = 'F';
typeout = 'C';
break;
default:
typeout = 'E';
break;
}
if( typeout != 'E' )
{
std::cout << tempin << typein
<<" = " << tempout
<< typeout << "\n \n";
}
else
{
std::cout<<"输入错误";
}
std::cout <<"请重新输入任何退出";
std::cin.get();
}
|
|