+ 7

[SOLVED] Question about switch statement

case 2: if (((year % 4 == 0) && !(year % 100 == 0)) || (year % 400 == 0)) numDays = 29; else numDays = 28; break; This is used to find the correct number of days in February using a switch statement. Can someone please break down what is happening using explanation or psuedocode. (What I'm having trouble understanding is the modulus) Thank you very much.

10th Jan 2017, 6:54 PM
Dalton Ponder
Dalton Ponder - avatar
2 Réponses
+ 7
This code is checking the leap year rules. Those rules say that there is a leap year every four years except if the year is a multiple of 100 except when it's a multiple of 400.
10th Jan 2017, 7:12 PM
James Durand
James Durand - avatar
+ 5
After looking at it more closely, and with your answer, I understand now. Thank you!
10th Jan 2017, 7:51 PM
Dalton Ponder
Dalton Ponder - avatar