+ 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.
2 Respuestas
+ 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.
+ 5
After looking at it more closely, and with your answer, I understand now. Thank you!