So basically this is for class. I do not want you guys to do my work. I am just lost in which direction to head.
the program takes in starting date and ending dates..and then its supposed to generate a list of dates in between the starting and ending date.
for example...i put may2nd 2009 to may4th 2009
its going to generate:
may2nd 2009
may3rd 2009
may4th 2009
I don't know if I should use Unix time to do this or use switch statements to do this or use loops to do this program. somebody whose knowledgeable at c programming language should know the most simplistic solution. help!
Generating dates between starting date and ending date in c programming?
You may need a table (structure) to store how many days are in each month. You could also do it with a series of "if"s. That's how you'll be able to cross over from say, may31st to june1st. The table would also be useful to verify your input dates (look for non-existent months), and to use the stored months as a basis for your parsing of the input (parse the input into may 2 2009). Another table could be used to track which suffix goes on which number (1 gets st, 2 gets nd), etc.
Reply:ok, it's been a long time since I've used C.
But the best logic to me would be to:
1. get the difference in days between the 2 dates. ie = 3
2. Now make a loop 0 to {diff} -1
3. Add the loop count of days to the starting date
VB Example:
Dim StartDate as Date="5/2/09"
Dim EndDate as Date="5/4/09"
Dim dd as Integer = datediff("d",StartDate,EndDate)
For d=0 to dd-1
Console.Writeline(dateadd("d",d,StartDat...
Next
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment