Quick if statement help!

1
2
3
4
5
6
7
8
    if ((( Year % 4 == 0) && (! ( Year % 100 == 0))) || (( Year % 4 == 0) && (! ( Year % 100 == 0))&&( Year % 400 == 0)))
    {
           cout<<"The Year "<<Year<<" is a leap year!!"<<endl;
    
    else
    
           cout<<Year<<" is not a leap year."<<endl;
    }


with this code, I seem to be getting these error message with my "else"

In function `int main()':
expected primary-expression before "else"
expected `;' before "else"


I have tried another set of brackets around the else but that doesn't do anything either.
Last edited on
1
2
3
4
5
6
7
8
if ((( Year % 4 == 0) && (! ( Year % 100 == 0))) || (( Year % 4 == 0) && (! ( Year % 100 == 0))&&( Year % 400 == 0)))
    {
           cout<<"The Year "<<Year<<" is a leap year!!"<<endl;
    } // HERE
    else
    { // HERE
           cout<<Year<<" is not a leap year."<<endl;
    }


Thank You! That worked.

One more question, if I wanted to make it so my program terminates if "Year" is a negative, how exactly would I go about doing that?

Is there a way to terminate out of an if statement if Year is negative?

Last edited on
Topic archived. No new replies allowed.