Program- calculate # of days between two days

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2007
Posts: 8
Reputation: youngone is an unknown quantity at this point 
Solved Threads: 0
youngone youngone is offline Offline
Newbie Poster

Program- calculate # of days between two days

 
0
  #1
Feb 26th, 2007
"Develop a program that can be used to calculate the number of days between any two days from 1/1/1900 through 12/31/2099

The main program will call the same function twice- once for each date and have an integer returned to it each time.

The function will prompt for a year, month and day(in that seqeunce)

After receiving both dates, the program will then determine the number of days between the two dates.

The normal year array should contain:
  1. {0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 304, 335, 366};

any help is much appreciated
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: Program- calculate # of days between two days

 
0
  #2
Feb 26th, 2007
We'd love to help you, but you must first read this. Then post your latest attempt, encased within code tags (and tell us what's not working so we don't have to guess).

Thanks
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Program- calculate # of days between two days

 
0
  #3
Feb 27th, 2007
I dunno, maybe actually try it for yourself rather than wandering from board to board in the hope that someone will spoon-feed you the answer.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 8
Reputation: youngone is an unknown quantity at this point 
Solved Threads: 0
youngone youngone is offline Offline
Newbie Poster

Re: Program- calculate # of days between two days

 
0
  #4
Feb 28th, 2007
I'm not looking to be spoon fed an answers
i'm looking for help!!!
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: Program- calculate # of days between two days

 
0
  #5
Feb 28th, 2007
>I'm not looking to be spoon fed an answers
Then show that you're willing to try. Post your latest coding attempt at it.

>i'm looking for help!!!
We'll help you once you post what you've already tried.
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 8
Reputation: youngone is an unknown quantity at this point 
Solved Threads: 0
youngone youngone is offline Offline
Newbie Poster

Re: Program- calculate # of days between two days

 
0
  #6
Feb 28th, 2007
OK , but how do i paste my code into this message box?
it's not giving me the option
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: Program- calculate # of days between two days

 
0
  #7
Feb 28th, 2007
>OK , but how do i paste my code into this message box?
  1. First of all type your message text
  2. Type [code]
  3. Insert some spaces, then type [/code]
  4. Paste your code in between the space that you made between the code tags
I'm assuming of course, that you know how to use your clipboard to copy items.
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 8
Reputation: youngone is an unknown quantity at this point 
Solved Threads: 0
youngone youngone is offline Offline
Newbie Poster

Re: Program- calculate # of days between two days

 
0
  #8
Feb 28th, 2007
Ok here is the code

I am new to the array concept, i know how to initialize them but that is it
How would i use the below arrays to add the days together

  1. #include <iostream>
  2. #include <math.h>
  3. #include <stdlib.h>
  4.  
  5. int main(void)
  6. {
  7. int month = 0;
  8. int month2 = 0
  9. int day = 0;
  10. int day2 = 0;
  11. int year = 0;
  12. int year2 = 0;
  13. numofdays = 0;
  14. julianDate = 0;
  15.  
  16. const int DaysInMonth[13] = {0,31,28,31,30,31,30,31,31.30,31,30,31};
  17. const int DaysInYear[13] = {0,0,31,59,90,120,151,181,212,243,273,304,334,365};
  18. const int DaysInLeapYear[13] = {0,0,31,60,91,121,152,182,213,244,274,305,335,366};
  19.  
  20. cout << "\n Calculates # of days between dates" << endl;
  21. cout << "\n give a date (ex: 2 28 2007):"<< endl;
  22. cin >> month >> day >> year;
  23.  
  24. if (month < 0 || month > 12 || day < 0 || day >31 || year > 1900 ||| year < 2099 )
  25. {
  26. cout << "One of the numbers you entered is incorrect\n";
  27. cout << "try entering it again (ex: 2 28 2007): ";
  28. cin >> month >> day >> year;
  29. }
  30.  
  31. cout << "\n give another date" << endl;
  32. cin >> month2 >> day2 >> year2 << endl;
  33.  
  34. if (month2 < 0 || month2 > 12 || day2 < 0 || day2 >31 || year2 > 1900 ||| year2 < 2099 )
  35. {
  36. cout << "One of the numbers you entered is incorrect\n";
  37. cout << "Try entering it again (ex: 2 28 2007): ";
  38. cin >> month2 >> day2 >> year2;
  39. }
  40.  
  41. juliandate =
  42.  
  43.  
  44.  
  45. cout << month << day << year << endl;
  46. cout << month2 << day2 << year2 << endl;
  47. cout << "# of days between these dates is: " << numofdays;
  48.  
  49. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: Program- calculate # of days between two days

 
0
  #9
Feb 28th, 2007
  1. #include <iostream>
  2. #include <math.h>
  3. #include <stdlib.h>
Alright - so which language are you trying to write in: C or C++? stdlib.h is a C header, and if you really need to use C functions (which I can't seem to find any in your code below) then you can use include <cstdlib> instead.

Since when are there 13 months in a year? And why are you keeping track of the number of days in each year; all you need is a second array for leap year.

Then you can calculate which years are leap years by using a starting year that you know is a leap year (drat, I can't remember when was our last leap year) and then comparing it to the year entered by the user. Hint: you'll need the % (modulos) operator.

The rest should be fairly easy; all you need to do is subtract years and multiply it by the number of days in the year you found earlier, multiply the difference of months by looking up the month array, and then adding the remainig days (if that made any sense at all).
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 8
Reputation: youngone is an unknown quantity at this point 
Solved Threads: 0
youngone youngone is offline Offline
Newbie Poster

Re: Program- calculate # of days between two days

 
0
  #10
Mar 1st, 2007
Oops, i don't know why I put 13 in that array

Code i am using is C++

Last night was finally able to get the julian date formula from my instructor is it as follows:
  1. jdate = year - 1900;
  2. jdate = year * 365 +((year-1)/4) + DaysInYear[month] + day

or for leap year:
  1. jdate = year - 1900;
  2. jdate = year * 365 +((year-1)/4) + DaysInLeapYear[month] + day

so later tonight I'm going to add this to my assignment and hopefully it compile just fine, ending this assignemtn and it's important to since I have now fallen behind the rest of the class
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC