Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I keep getting an error \" \'else\' without a previous \' if \' \" -------------

ID: 3544467 • Letter: I

Question

I keep getting an error " 'else' without a previous ' if ' "

-----------------------------------------------------------

# include <iostream>

# include <iomanip>

# include <cmath>

using namespace std;

int main ( )

{


int year, month, days;


cout << " Please Enter Year : ";

cin >> year;

cout << " Please Enter Month: ";

cin >> month;

cout << endl;


if (month == 2);{

    if (year%400 == 0 || (year%100 != 0 && year%4 == 0));

        days = 29;

    else

        days = 28;

}

if (month != 2);{

    if (month == 4 || month == 6 || month == 9 || month == 11);

        days = 30;

    else

        days =31;

}


cout << " There are " << days << " in the month " << month << " of the year " << year << endl;


return 0;

}

Explanation / Answer

i got it right you haved not used IF function correctly wherever you encounter IF just remove ; it is not the correct syntax then check out your programme i have kept it corrected though

# include <iostream>

# include <iomanip>

# include <cmath>

using namespace std;

int main ( )

{


int year, month, days;


cout << " Please Enter Year : ";

cin >> year;

cout << " Please Enter Month: ";

cin >> month;

cout << endl;


if (month == 2);{

if (year%400 == 0 || (year%100 != 0 && year%4 == 0))

days = 29;

else

days = 28;

}

if (month != 2){

if (month == 4 || month == 6 || month == 9 || month == 11)

days = 30;

else

days =31;

}


cout << " There are " << days << " in the month " << month << " of the year " << year << endl;


return 0;

}