如何修复此预期表达式错误?
How do I fix this Expected Expression Error?
我正在尝试为项目编写代码,并且在我的 if else
语句中我想将 SWI 大于或等于 305 且小于或等于 395。我将如何在代码中放置这些限制?我尝试使用 <=
和 >=
,但我认为位置不正确,我对如何修复它感到困惑。
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double T,SWI,W;
cout << "HELLO USER, PLEASE ENTER THE TEMPERATURE AND WIND SPPED TO PREDICT WEATHER FORECAST";
cin >> T, W;
SWI = 150*log10(T-49)+0.41*W+125*W/T;
if (SWI < 305);{
cout << "There is a low risk of severe thunderstorms.\n";
cout << "However, still remain indoors and keep dry until the storm passes\n";
}else if (SWI >= 305,SWI <= 395); {
cout<< "Severe thunderstorms possible.\n";
cout << "Please remain indoors and expect turbulant winds.\n";
}else if(SWI > 395);{
cout << "Severe thunderstorms imminent.\n";
cout << "Stay off the roads and avoid any tall trees, possibility of tornadoes suspected.\n";
}
return 0;
} // end program
您有一些语法错误。你应该有这样的东西:
if (SWI< 305){ //remove ; in every if and else
cout<< "There is a low risk of severe thunderstorms.\n";
cout << "However, still remain indoors and keep dry until the storm passes\n";
}else if (SWI<=395) { // if the execution falls in here is because SWI>=305
cout<< "Severe thunderstorms possible.\n";
cout << "Please remain indoors and expect turbulant winds.\n";
}else if(SWI > 395){
cout<< "Severe thunderstorms imminent.\n";
cout << "Stay off the roads and avoid any tall trees, possibility of tornadoes suspected.\n"; }
return 0; }
语法错误太多。更正后的版本。
您可能还需要考虑检查 T
。它必须是 >49
否则日志函数得到一个 -ve
输入。
#include <iostream>
#include <cmath>
int main()
{
using namespace std;
double T,SWI,W;
cout << "HELLO USER, PLEASE ENTER THE TEMPERATURE AND WIND SPEED TO PREDICT WEATHER FORECAST";
cin >> T;
cin >> W;
SWI = (150*log10(T-49))+(0.41*W)+(125*W/T);
if (SWI < 305){
cout << "There is a low risk of severe thunderstorms.\n";
cout << "However, still remain indoors and keep dry until the storm passes\n";
}else if (SWI <= 395) {
cout<< "Severe thunderstorms possible.\n";
cout << "Please remain indoors and expect turbulent winds.\n";
}else {
cout << "Severe thunderstorms imminent.\n";
cout << "Stay off the roads and avoid any tall trees, possibility of tornadoes suspected.\n";
}
return 0;
} // end program
我正在尝试为项目编写代码,并且在我的 if else
语句中我想将 SWI 大于或等于 305 且小于或等于 395。我将如何在代码中放置这些限制?我尝试使用 <=
和 >=
,但我认为位置不正确,我对如何修复它感到困惑。
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double T,SWI,W;
cout << "HELLO USER, PLEASE ENTER THE TEMPERATURE AND WIND SPPED TO PREDICT WEATHER FORECAST";
cin >> T, W;
SWI = 150*log10(T-49)+0.41*W+125*W/T;
if (SWI < 305);{
cout << "There is a low risk of severe thunderstorms.\n";
cout << "However, still remain indoors and keep dry until the storm passes\n";
}else if (SWI >= 305,SWI <= 395); {
cout<< "Severe thunderstorms possible.\n";
cout << "Please remain indoors and expect turbulant winds.\n";
}else if(SWI > 395);{
cout << "Severe thunderstorms imminent.\n";
cout << "Stay off the roads and avoid any tall trees, possibility of tornadoes suspected.\n";
}
return 0;
} // end program
您有一些语法错误。你应该有这样的东西:
if (SWI< 305){ //remove ; in every if and else
cout<< "There is a low risk of severe thunderstorms.\n";
cout << "However, still remain indoors and keep dry until the storm passes\n";
}else if (SWI<=395) { // if the execution falls in here is because SWI>=305
cout<< "Severe thunderstorms possible.\n";
cout << "Please remain indoors and expect turbulant winds.\n";
}else if(SWI > 395){
cout<< "Severe thunderstorms imminent.\n";
cout << "Stay off the roads and avoid any tall trees, possibility of tornadoes suspected.\n"; }
return 0; }
语法错误太多。更正后的版本。
您可能还需要考虑检查 T
。它必须是 >49
否则日志函数得到一个 -ve
输入。
#include <iostream>
#include <cmath>
int main()
{
using namespace std;
double T,SWI,W;
cout << "HELLO USER, PLEASE ENTER THE TEMPERATURE AND WIND SPEED TO PREDICT WEATHER FORECAST";
cin >> T;
cin >> W;
SWI = (150*log10(T-49))+(0.41*W)+(125*W/T);
if (SWI < 305){
cout << "There is a low risk of severe thunderstorms.\n";
cout << "However, still remain indoors and keep dry until the storm passes\n";
}else if (SWI <= 395) {
cout<< "Severe thunderstorms possible.\n";
cout << "Please remain indoors and expect turbulent winds.\n";
}else {
cout << "Severe thunderstorms imminent.\n";
cout << "Stay off the roads and avoid any tall trees, possibility of tornadoes suspected.\n";
}
return 0;
} // end program