2016-09-21 97 views
-3

嗨只是想知道爲什麼這不起作用,因爲它現在只打印出華氏溫度,無論我選擇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; 
    } 
+1

做的研究最少在這裏發佈一個新的問題,請之前! –

+5

'||'不符合你的想法! – drescherjm

回答

3

這可能會更好地工作:

if (unit == 'c' || unit == 'C') 
+0

不會評論足夠嗎?這與問題標題有什麼關係? –

+0

謝謝我的朋友 –

+0

它證明發布的代碼沒有做OP的想法。 – duffymo