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

6th Oct 2022, 6:26 AM
Sashunia
Sashunia - avatar
12 Answers
+ 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.
7th Oct 2022, 1:27 PM
Brian
Brian - avatar
+ 1
Accurate result means you asking about choosing accurate data types you can use double if you have to deal with decimals
6th Oct 2022, 7:23 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 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.
6th Oct 2022, 5:58 PM
Brian
Brian - avatar
+ 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
7th Oct 2022, 1:37 AM
Emerson Prado
Emerson Prado - avatar
+ 1
Brian thanks, I've just done as you recommend
7th Oct 2022, 1:34 PM
Sashunia
Sashunia - avatar
0
ASR Brian so for more accuracy I need to set an input of date of birth than just age?
6th Oct 2022, 6:44 PM
Sashunia
Sashunia - avatar
0
Emerson Prado agreed but I don't have any idea how to code it
7th Oct 2022, 6:38 AM
Sashunia
Sashunia - avatar
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?
7th Oct 2022, 10:51 AM
Emerson Prado
Emerson Prado - avatar
0
Emerson Prado could it be done with the help of module operator? Smth like if(age %= 4){ year++ }
7th Oct 2022, 1:27 PM
Sashunia
Sashunia - avatar
- 1
Hello
8th Oct 2022, 5:45 AM
Mst Shanaz
Mst Shanaz - avatar
- 1
What's is video tag
8th Oct 2022, 5:45 AM
Mst Shanaz
Mst Shanaz - avatar
- 1
I want know
8th Oct 2022, 5:46 AM
Mst Shanaz
Mst Shanaz - avatar