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-

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

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

-___-

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 think this will help...

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?

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?

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.

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?

Simple loop with a test inside.

would it be a for loop with an if statement?

Duh.... :icon_wink:

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.

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

what do i do when the years are not the same? i need to be able to change the years

what do i do when the years are not the same? i need to be able to change the years

That has already been answered.

everything is fixed. i went into crunch mode and my program is done, with comments, and runs like a dream. i started getting frantic in my last posts and i apologize, i cannot thank you guys enough. i will try and troll this site with what i know to help out too. i will definitely tell my friends about this site. it's the best. here is my finished program for everyone, it's pretty sweet
http://people.clarkson.edu/~bujoldea/prog03.cpp
thanks again eveyone
-Evan

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.