C++ c++;华氏或摄氏转换器
嗨,我只是想知道为什么这不起作用,现在它只打印出华氏温度,不管我选择c还是f。plz帮助C++ c++;华氏或摄氏转换器,c++,C++,嗨,我只是想知道为什么这不起作用,现在它只打印出华氏温度,不管我选择c还是f。plz帮助 #include <iostream> using namespace std; int main() { char unit; float degrees = 0.0; float Farenheit, Celsius; cout << "Enter the temperature unit you are currently in (f or
#include <iostream>
using namespace std;
int main()
{
char unit;
float degrees = 0.0;
float Farenheit, Celsius;
cout << "Enter the temperature unit you are currently in (f or c): ";
cin >> unit;
cout << "Enter the temperature in degrees: ";
cin >> degrees;
if ( unit == 'c' || 'C')
{
Farenheit = (degrees - 32) / 9 * 5.0;
cout << "The degrees in Farenheit are: " << Farenheit << endl;
}
else if ( unit == 'f' || 'F')
{
Celsius = (degrees - 32) * 5.0/9;
cout << "The degrees in Celsius is: " << Celsius << endl;
}
return 0;
}
#包括
使用名称空间std;
int main()
{
炭单元;
浮动度=0.0;
浮式法伦海特,摄氏度;
cout>单位;
cout>度;
如果(单位='c'| |'c')
{
法伦海特=(32度)/9*5.0;
cout这可能更有效:
if ( unit == 'c' || unit == 'C')
在发布新问题之前,请至少做一点调查!|
没有按照您的想法工作!可能重复的问题难道评论不够吗?这与问题标题有什么关系?谢谢我的朋友。它说明发布的代码没有按照OP的想法执行。或者如果(toupper(unit)='C')
。甚至如果(strhr(“Cc”,unit))
。是的,任何一种都会更好。