2014-09-30 112 views
-1

因此,我正在編寫一個C++代碼,應該詢問用戶是否要使用攝氏度或華氏度,然後詢問他們的度數,然後將其轉換。我的程序不會編譯,抱怨編譯器期望一個標識符並且我錯過了一個;在識別char之前。請詳細說明我的代碼到底出了什麼問題。請記住,我是新的,任何信息非常感謝,但我不會理解更復雜的術語/代碼。輸入攝氏溫度/華氏然後轉換

#include <iostream> 
using namespace std; 
int main() 
{ 
char 'C'; 
double degree; 
int degree_type; 


cout << "What's the Degree type?: "; 
cin >> degree_type; 


if (degree_type == 'C') 
{ 

cout << "What's the Temperature?: "; 
cin >> degree; 

cout << degree << " degrees Celsius is = " << 9/5 * degree + 32 << " Degrees Fahrenheit" << endl; 

} 

else 
{ 
cout << "What's the Temperature?: "; 
cin >> degree; 

cout << degree << " degrees Fahrenheit is = " << (degree - 32) * 5/9 << " Degrees Celsius" << endl; 

} 

return 0; 
} 
+1

'char'C';'是沒有意義的。去掉它。 – 2014-09-30 01:53:53

+0

好的,在這樣做的時候我可以指出結果,這很好,但是它不會讓我變化程度。爲什麼不? – 2014-09-30 01:59:15

+0

在第一個'cin'之後調用'cin.ignore();'清除流中的換行符。 – 2014-09-30 02:04:22

回答

1

您必須刪除char'C'並將「degree_type」的類型更改爲char,類似這樣。

//char 'C'; Comment this line or remove 
double degree; 
char degree_type; // change this 
+0

這個修復功能非常完美,非常感謝您的幫助。我終於明白在哪裏以及如何有效地使用char。再次感謝您的幫助和支持我! – 2014-09-30 02:18:21