User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,571 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,615 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1955 | Replies: 12 | Solved
Reply
Join Date: Oct 2007
Posts: 7
Reputation: bujoldea is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bujoldea bujoldea is offline Offline
Newbie Poster

Question array structs, size swap functions, the amount of days between to dates

  #1  
Oct 27th, 2007
my intro to comp science teacher gave me an assignment to:
1) enter two different dates with the use of stucts
2) use a swap function to arrange each date in order from earliest to latest
3) use functions to calculate the number of days between the two dates
4) cout to the user the amount of days
5) other misc shit

i've put over 20 hours worth of work into my program, which i am immensely proud of, in a matter of days because this weekend i am visiting my love. but i digress, i cannot figure out how to calculate the number of days in the months between the two months chosen and add the number of days between the days that are chosen.

my code is a bit robust, and to be honest im not sure how to go putting my code in here, so i have a link to my code in a public directory

http://people.clarkson.edu/~bujoldea/prog03.cpp

i think i may have worked myself into a corner with how complicated everything has gotten, but im too proud of the work ive done on this to scrap it. my prog is due on monday and all i need is a little push on how to make the code ive constructed calculate the number of days in the months between the months ive chosen (the months are already enumerated) and then add the days. please help me out, i will be forever grateful

-Evan-
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2006
Posts: 2,781
Reputation: WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold 
Rep Power: 15
Solved Threads: 229
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: array structs, size swap functions, the amount of days between to dates

  #2  
Oct 27th, 2007
DaysFirst = How many days left in the first month
DaysLast = essentially the day of the last month - 1
DaysMonth = number of days in each month between the two months

Add them all together.

Example:
4-May-2007 to 23-Sep-2007

DaysFirst = 27 (31 days in May - 4)
DaysLast = 22 (day of the month - 1)
DaysMonth = 92 (June/30 July/31 August/31)

Total= 141 days
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
Reply With Quote  
Join Date: Oct 2007
Posts: 7
Reputation: bujoldea is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bujoldea bujoldea is offline Offline
Newbie Poster

Re: array structs, size swap functions, the amount of days between to dates

  #3  
Oct 27th, 2007
i've enumerated the months with the number of days in each month

how do i rig it so that what ever the user types for their two months counts the number of days in the months between? could i use a for loop like:

for (int i=first month; i<last month; i++)

my brain is fried

-___-
Reply With Quote  
Join Date: Jul 2007
Posts: 54
Reputation: tracethepath is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 4
tracethepath's Avatar
tracethepath tracethepath is offline Offline
Junior Poster in Training

Re: array structs, size swap functions, the amount of days between to dates

  #4  
Oct 27th, 2007
Originally Posted by bujoldea View Post
i've enumerated the months with the number of days in each month

how do i rig it so that what ever the user types for their two months counts the number of days in the months between? could i use a for loop like:

for (int i=first month; i<last month; i++)

my brain is fried

-___-


what you can do is

no of days=daysfirst+dayslast; (as told by the person who replied earlier)

and then

for(int i=(first month+1); i<last month; i++)
no of days+=days_in_month[i];

i think this will help...
With Regards...
Reply With Quote  
Join Date: May 2006
Posts: 2,781
Reputation: WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold 
Rep Power: 15
Solved Threads: 229
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: array structs, size swap functions, the amount of days between to dates

  #5  
Oct 27th, 2007
Originally Posted by bujoldea View Post
i've enumerated the months with the number of days in each month

how do i rig it so that what ever the user types for their two months counts the number of days in the months between? could i use a for loop like:

for (int i=first month; i<last month; i++)

my brain is fried

-___-

Sort of. If you don't want the first month added use
for (int i > first month; i < last month; i++)

But, what if your dates are 15-Sep-2006 to 22-May-2007?
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
Reply With Quote  
Join Date: Oct 2007
Posts: 7
Reputation: bujoldea is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bujoldea bujoldea is offline Offline
Newbie Poster

Re: array structs, size swap functions, the amount of days between to dates

  #6  
Oct 28th, 2007
ok, so i think i have the month thing down. the question now is years
would it be safe to say that the calculation for the number of days between years would be

(larger year - smaller year)*365.25 - 365

subtracting the extra 365 to count for the months and the days and multiplying it by 365.25 for leap year (i know its a bit in accurate, but im a first year student and she should be proud i made it this far)

waddayathink?
Reply With Quote  
Join Date: May 2006
Posts: 2,781
Reputation: WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold 
Rep Power: 15
Solved Threads: 229
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: array structs, size swap functions, the amount of days between to dates

  #7  
Oct 28th, 2007
Close, but not close enough. You'd get the same answer if the years were 2001-2005 and 2004-2008 but in fact the former has one day les because there's only one leap year. You need to look at each year individually and deal with LY. Simple loop with a test inside.
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
Reply With Quote  
Join Date: Oct 2007
Posts: 7
Reputation: bujoldea is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bujoldea bujoldea is offline Offline
Newbie Poster

Re: array structs, size swap functions, the amount of days between to dates

  #8  
Oct 28th, 2007
would it be a for loop with an if statement?

for every year between one and the other, use my leap year function to test if each year is a leap year and for every year that its true, add one day?
Reply With Quote  
Join Date: May 2006
Posts: 2,781
Reputation: WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold 
Rep Power: 15
Solved Threads: 229
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: array structs, size swap functions, the amount of days between to dates

  #9  
Oct 29th, 2007
Originally Posted by bujoldea View Post
Originally Posted by WaltP View Post
Simple loop with a test inside.
would it be a for loop with an if statement?
Duh....

Originally Posted by bujoldea View Post
for every year between one and the other, use my leap year function to test if each year is a leap year and for every year that its true, add one day?

Yes.
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
Reply With Quote  
Join Date: Oct 2007
Posts: 7
Reputation: bujoldea is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bujoldea bujoldea is offline Offline
Newbie Poster

Re: array structs, size swap functions, the amount of days between to dates

  #10  
Oct 29th, 2007
heres my code once more. everything should be fine, but my answers are off by quite a large amount

http://people.clarkson.edu/~bujoldea/prog03.cpp

run it and see what i ****ed up
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 6:00 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC