what does this function mean?
Feb 11, 2013 at 3:20am UTC
Hi everyone,
I have this function I did not understand it and I don't get the condition in the if statement. If you can please explain this function.
Thank you in advance.
1 2 3 4 5 6 7 8
bool DateAndTime::leapYear()
{
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
return true ;
else
return false ;
}
Feb 11, 2013 at 4:41am UTC
if (year % 400 == 0
If year is divisible by 400 it is leap year
||
OR
(year % 4 == 0 && year % 100 != 0))
if year is divisible by 4 AND(&&) NOT(!) divisible by 100 year is leap year.
Feb 12, 2013 at 7:44am UTC
I thank you eraggo
so much for your explanation. it helps a lot.
Feb 12, 2013 at 8:14am UTC
The function can be rewritten much simpler
1 2 3 4 5
bool DateAndTime::leapYear()
{
return ( ( year % 400 == 0 ) || ( year % 4 == 0 && year % 100 != 0 ) );
}
Topic archived. No new replies allowed.