Search code examples
c++projectcodeblocks

How do I fix this Expected Expression Error?


I am trying to write a code for a project, and in my if else statements I want to put that the SWI is greater than or equal to 305 and less than or equal to 395. How would I place those limitations in the code? I tried using <= and >=, but I do not think the placement is correct, and I am confused on how to fix it.

#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

Solution

  • There are too many syntactic errors. Corrected version below.

    also you might need to consider a check on T. It must be >49 else the log function gets a -ve input.

    #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