所以我写了一个c ++代码,该代码应该询问用户是否要使用Celsius或Fahrenheit,然后向他们询问度数,然后转换它。我的程序不会编译,抱怨编译器需要一个标识符并且我错过了一个;在确定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;
}
答案 0 :(得分:1)
你必须删除char&#39; C&#39;并更改&#34; degree_type&#34;的类型;对char来说,就像这样。
//char 'C'; Comment this line or remove
double degree;
char degree_type; // change this