-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;
}
'char'C';'是沒有意義的。去掉它。 – 2014-09-30 01:53:53
好的,在這樣做的時候我可以指出結果,這很好,但是它不會讓我變化程度。爲什麼不? – 2014-09-30 01:59:15
在第一個'cin'之後調用'cin.ignore();'清除流中的換行符。 – 2014-09-30 02:04:22