•
•
•
•
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
![]() |
•
•
Join Date: Oct 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
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-
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
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
-- Pearl Williams
•
•
•
•
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...
•
•
•
•
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
-- Pearl Williams
•
•
Join Date: Oct 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
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?
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.
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
-- Pearl Williams
•
•
•
•
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?
Yes.
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
-- Pearl Williams
•
•
Join Date: Oct 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
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
http://people.clarkson.edu/~bujoldea/prog03.cpp
run it and see what i ****ed up
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Programming student find distances btwn cities using array of structs (C++)
- definig a 3d array of unknown size (Visual Basic 4 / 5 / 6)
- C++ Array help needed (C++)
- working with array of structs (C++)
- 1-D array (C)
- help calculating days (C++)
- erge and Heap...which is really faster (C++)
- how to increase the size of an array? (C)
Other Threads in the C++ Forum
- Previous Thread: beginner of c++
- Next Thread: Structure of arrays



Linear Mode