0
I did some simple code that calculates age in days
How can I modify including leap years so it will calculate more accurate? https://code.sololearn.com/cUHtPAkc9S2t/?ref=app
12 ответов
+ 3
Sashunia
Hint to increase by leap years:
1. Multiply age by 365.2425.
2. Done.
The number 365.2425 is the precise number of days in a year. The leap year rules were derived from that number. Originally 365 was thought to be sufficient, but that 0.2425 day started adding up to full days and causing mismatch with the seasons, slipping nearly a day every four years. Though it's just under one day every four years, so they also skip a leap year when the four-year rule adds up to one day too many.
+ 1
Accurate result means you asking about choosing accurate data types you can use double if you have to deal with decimals
+ 1
Multiply by 365.2425. It would not be exact, but somewhat accurate on average.
A much bigger inaccuracy occurs by not counting number of days since the person's last birthday.
+ 1
Since the input is only the age in years, not taking into account the birth year and date, I would just add one day for each 4 years
+ 1
Brian thanks, I've just done as you recommend
0
Emerson Prado agreed but I don't have any idea how to code it
0
Sashunia
1. How do you calculate a number which corresponds to one year on each four?
2. How do you add it to the day count?
0
Emerson Prado could it be done with the help of module operator?
Smth like
if(age %= 4){
year++
}
- 1
Hello
- 1
What's is video tag
- 1
I want know