嗨只是想知道爲什麼這不起作用,因爲它現在只打印出華氏溫度,無論我選擇c還是f。 plz幫助C++華氏溫度或攝氏度轉換器
#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;
}
做的研究最少在這裏發佈一個新的問題,請之前! –
'||'不符合你的想法! – drescherjm