输入摄氏度/华氏度,然后进行转换

Input Celsius/Fahrenheit then convert

本文关键字:然后 转换 摄氏度 输入      更新时间:2023-10-16

所以我正在编写一个c++代码,该代码应该询问用户是想使用摄氏度还是华氏度,然后询问他们度数,然后转换它。我的程序不会编译,抱怨编译器需要一个标识符,而我缺少一个;在识别字符之前。请详细地告诉我我的代码到底出了什么问题。请记住,我是新来的,非常感谢提供任何信息,但我不会理解更复杂的术语/代码。

#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'并将"degree_type"的类型更改为char,类似这样。

//char 'C'; Comment this line or remove
double degree;
char degree_type; // change this
相关文章: