Implementing Leap Years

Hey, everyone!

I am working on my title Once in a Lifetime, which accurately calculates years and timeframes.

One thing I’m struggling to figure out a solution to is how I would code in leap year calculations on an if statement.

Typically, leap years are on any year that can evenly end in a 4. I have variables declared for tracking the current year at this time. I was considering a theory of if I could parse out the last digit on the integer (so if it ends in 4), but was unsure how I could implement this.

EDIT: Parsing out any integer that evenly ends on the 4th year, sorry for the confusion!

If anyone has any other methods, please feel free.

I greatly appreciate it!!!

This is fantastic, thank you so much!

The typical algorithm is:

You’ll need modulo.

2024 is a leap year, but it’s not divisible by 400. 1800 is not a leap year, but it’s divisible by 4.

2 Likes

Beat me to it. You can easily code it like this:

*temp year 2024
*temp is_leap_year false

*set is_leap_year ((year modulo 4) = 0)

Slightly more is needed to account for the exceptions, but that’s the crux of it.

Here’s it with the exceptions, since ChoiceScript ands can be annoying:

*set is_leap_year (((year modulo 4) = 0) and ((year modulo 100) != 0)) or ((year modulo 400) = 0)
3 Likes

Thank you to everyone for the help.

I’m still getting used to programming, so it’s been an up and down haha.

Thank you so much once again!

1 Like

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.