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;
}
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?
Your condition (a && b) || (a && b && c) is wrong.
First of all, (a && b) || (a && b && c) is equivalent to just (a && b && c) for all a,b,c. Second, there's no number that's divisible by 400 but not by 100.
if(Year<0)
{
cout<<"Since when can a year be negative?"<<endl;
}
elseif ((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;
}
cout<<endl;
That is what I changed it too... seems to be working :)