If Else Statements Issue

I agree that my if else statements are pretty convoluted but I was sure all the brackets and pairings within pairings matched up correctly yet I continue to get the error on visual studios that "illegal else without matching if".

I've looked over this so many, times I need a fresh pair of eyes to help me spot the problem:

bool isValidDate(int month, int day, int year) {

if (!isGregorianDate(month, day, year) || month > 12 || month < 1 || day > 31 || day < 1) {
return false;
}

else {

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

if (day > 30) {
return false;

}
else {
return true;


}
}

else if (month == 2) {

if (isLeapYear(year)) {

if (day > 29) {
return false;

}
else {
return true;

}
} if (!isLeapYear(year)) {

if (day > 28) {
return false;
else {
return true;
}
}
}
else {
}
}
}
closed account (LA48b7Xj)
This part is an error
1
2
3
4
5
6
7
8
if (day > 28)
{
    return false;
    else
    {
         return true;
    }
}


This might fix it
1
2
3
4
if (day > 28)            
    return false;
else                
    return true;


Last edited on
Thanks for your help but I decided to just rewrite it with less pairs inside pairs of statements.
Topic archived. No new replies allowed.