We were given an assignment to add a number of days to a date. So I would add for example 10 days to Jan 20, 2013. I understand operator overloading and I an ignoring the leap year issue for now, what I can't figure out is the logic needed to add a certain numbers of days to a specified date.
I've done programs in the past where you add hours and minutes, but this is easy because an hour is always 60 mins and a minute is always 60 seconds, so you can easily use % 60. But with months all the days are different.
Would it make sense to correspond every day with a certain number, then add the numbers and convert it back to a date? For example, Jan 1 is the first day of the year, so if I add 32 to Jan 1 I get the 32nd day of the year which is Feb 1. (if it's not a leap year). And I would convert 32 to Feb 1? I'm not sure how I would do it, but do you think that would make sense for an algorithm or am I totally overthinking this?
I'm sure there is already pre-written templates for this, but we have not been taught those so it needs to be done without using any library or template.
Im new to this so I probably will not be any help but if jan is 1-31 and feb is 32-58 than: Jan 20 + 30=50, 50 - 31 = 19 the result would be feb 19 which you might be able to do with an if or while statement.