![]() |
Help
once again I'm trying to write a program. This program determines the number of days between two dates that are input by the user. Must take into account leap years.
the program must: 1. at least 1 'if' statement 2. 1 switch statement 3. 1 loop structure 4. 2 functions, value returning and/or viod functions 1-3 may be implemented in the user defined functions rather than main function. I have started but not sure if I'm on thee right path. :
|
Re: Help
here is what one of your functions might look like
:
|
Re: Help
I'm sorry, I'm still confused....
|
Re: Help
Calculating the number of days between dates can be very tricky, especially if one of the two dates is before the gregorian calendar was invented. If you limit the two dates to be after 1970 then you can use the functions in time.h. create an object of struct tm, fill in the date, them call mktime() to get the number of seconds. Do the same for the second date. Then call datediff() to return the difference.
|
Re: Help
Yes, unless the assignment restricts you from using predefined functions, do what Ancient Dragon suggested. There's no sense in reinventing the wheel. Unless that's the purpose of this homework assignment.
|
Re: Help
ok, so can someone tell me what I'm doing wrong? I am so lost
Quote:
|
Re: Help
Read what Ancient Dragon said. You can use the function
mktime() to calculate the epoch of a date. Do that once for each date. Then use the function difftime() to figure out the number of days between the two. |
Re: Help
Another way to do it is to just convert both dates to days and subtract the two. Something like this.
:
unsigned int day1 = 1, month1 = 1, year1 = 2007;The above is not 100% accurate because it does not account for leap years. So I would create a loop to run from year 0 to year1 and from 0 to year2 and add 1 for each leap year found. There are probably faster ways to do it, but that will do. |
Re: Help
Quote:
|
Re: Help
i read what he wrote, I was going to give a time from from 1900-2099...anything below or beyond those years and you would get an error, and have to input another date...
|
| All times are GMT -5. The time now is 3:43 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC