I am completely new to programming and need to learn it fast. I have been set the task of creating a day countdown in C. I need the programme to workout the difference between two dates and display the number of days inbetween that period.
Could anyone put me in the right direction to help me code this. I have read basic tutorials, but am not sure where to go next.
Ahh, this is one of the first programs I ever wrote.
Should be as simple as subtracting the days between the two dates if the months are equal to one another.
Here are some snags you need to watch out for.
Two dates in different months, this should not be to hard you only need to calc how many days the first date is away from the end of the month, how many months in between (if start month > end month+1 so long as they are contained within the same year), if the months in between are 30 or 31 day months and then add that to the # of the day in the ending day
Watch out for dates that cross over years
Watch out for leap years. Detect leap year function really helps here.
You want to find documentation functions provided in time.h (if you use C) or ctime (if you use C++) headerfile. You do not want to create the algorithm yourself - leapyears, daylight savings etc. take care of that :)
To be more precise, you might want to know functions mktime() and difftime().
But where is the fun in that :P
Originally Posted by Maz
The fun? I guess nowhere. But the author's style of putting the question let me to assume he is not in this just for fun ;) I've been programming for fun and for my work - and believe me, while making it all yourself may be fun at times, it is not fun at all when someone is breathing at your neck...