Hello everyone! I've recently just started a new project to create an Age calculator in c++. I have made it so that it now successfully calculates your age. I also want it to calculate how old you are in months (and days. One step at a time) but I can't figure out how to do it.
I could do a "simple" subtraction but what if its the 2nd of november today and my birthday is the 21st February next year? How do I make it calculate the months in the right way?
If your question is how many days then you continue the calculation. However you'll quickly realize that this is not really all that meaningful because months vary in length. So your age is better described in years plus weeks and/or days even though leap years also intervene.
However, if you need to be absolutely accurate with months and days (and taking into account leap years), one way is to calculate from the start/end of the month in each case, in order to get the days right, and then add that result to the months number.
That means 2/11/2015 to 21/2/2016 is 0 years 2 (whole calendar) months and 49 days, which is a bit 'ordinary'.