【发布时间】:2014-09-30 01:52:15
【问题描述】:
所以我正在编写一个 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';毫无意义。删除它。 -
好的,这样做我可以计算出结果,这很好,但它不会让我输入可变度数。为什么不呢?
-
在第一个
cin之后调用cin.ignore();以清除流中的换行符。
标签: c++ char type-conversion