即使我已经声明了变量,我也不明白这个错误
int total;
int op;
int f;
int c;
int k;
cout<<" Type the number of corresponding conversion: ";
cin>>op;
if(op == 1)
{ cout<<"\nEnter Fahrenheit: ";
cin>>f;
cout<<endl<<(f-32) * .5556 = total<<"°C";
}
if(op == 2)
{
cout<<"\nEnter Celcius: ";
cin>>c;
cout<<endl<<(c*1.8)+32=total<<"°F";
}
if(op == 3)
{
cout<<"\nEnter Fahrenheit: ";
cin>>f;
cout<<endl<<5/9(f-32)+273=total<<"K";
}
if(op == 4)
{
cout<<"\nEnter Kelvin: ";
cin>>k;
cout<<endl<<(k-273.15)*9/5+32=total<<"°F";
}
if(op == 5)
{
cout<<"\nEnter Celcius: ";
cin>>c;
cout<<endl<<c+273.15=total<<"K";
}
if(op == 6)
{
cout<<"\nEnter Kelvin: ";
cin>>k;
count<<endl<<k-273.15=total<<"°C";
}
else
{
cout<<"\nInvalid Input";
}
我尝试了重新排列和更改,我期待如何在最少的帮助下让它工作
导致你的代码无法正常运行的原因有很多 -
iostream
cin 和 cout 的导入std
如果没有它,您需要使用 std::cout
而不是 cout
Celsius
并具有相应的 Fahrenheit
输出
op
),您的操作也需要处于浮动状态才能到达Invalid input
块#include <iostream>
using namespace std;
int main() {
float total;
float op;
float f;
float c;
float k;
cout << "Type the number of corresponding conversion: ";
cin >> op;
if (op == 1) {
cout << "\nEnter Fahrenheit: ";
cin >> f;
total = (f - 32) * 5 / 9;
cout << endl << total << "°C";
}
else if (op == 2) {
cout << "\nEnter Celsius: ";
cin >> c;
total = c * 9 / 5 + 32;
cout << endl << total << "°F";
}
else if (op == 3) {
cout << "\nEnter Fahrenheit: ";
cin >> f;
total = 5 * (f - 32) / 9 + 273;
cout << endl << total << "K";
}
else if (op == 4) {
cout << "\nEnter Kelvin: ";
cin >> k;
total = (k - 273.15) * 9 / 5 + 32;
cout << endl << total << "°F";
}
else if (op == 5) {
cout << "\nEnter Celsius: ";
cin >> c;
total = c + 273.15;
cout << endl << total << "K";
}
else if (op == 6) {
cout << "\nEnter Kelvin: ";
cin >> k;
total = k - 273.15;
cout << endl << total << "°C";
}
else {
cout << "\nInvalid Input";
}
return 0;
}