| | |
Program- calculate # of days between two days
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2007
Posts: 8
Reputation:
Solved Threads: 0
"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:
any help is much appreciated
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:
C++ Syntax (Toggle Plain Text)
{0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 304, 335, 366};
any help is much appreciated
"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.
All my posts may be freely redistributed under the terms of the MIT license.
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.
>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.
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.
All my posts may be freely redistributed under the terms of the MIT license.
>OK , but how do i paste my code into this message box?
- First of all type your message text
- Type [code]
- Insert some spaces, then type [/code]
- Paste your code in between the space that you made between the code tags
"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.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
Join Date: Feb 2007
Posts: 8
Reputation:
Solved Threads: 0
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
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
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <math.h> #include <stdlib.h> int main(void) { int month = 0; int month2 = 0 int day = 0; int day2 = 0; int year = 0; int year2 = 0; numofdays = 0; julianDate = 0; const int DaysInMonth[13] = {0,31,28,31,30,31,30,31,31.30,31,30,31}; const int DaysInYear[13] = {0,0,31,59,90,120,151,181,212,243,273,304,334,365}; const int DaysInLeapYear[13] = {0,0,31,60,91,121,152,182,213,244,274,305,335,366}; cout << "\n Calculates # of days between dates" << endl; cout << "\n give a date (ex: 2 28 2007):"<< endl; cin >> month >> day >> year; if (month < 0 || month > 12 || day < 0 || day >31 || year > 1900 ||| year < 2099 ) { cout << "One of the numbers you entered is incorrect\n"; cout << "try entering it again (ex: 2 28 2007): "; cin >> month >> day >> year; } cout << "\n give another date" << endl; cin >> month2 >> day2 >> year2 << endl; if (month2 < 0 || month2 > 12 || day2 < 0 || day2 >31 || year2 > 1900 ||| year2 < 2099 ) { cout << "One of the numbers you entered is incorrect\n"; cout << "Try entering it again (ex: 2 28 2007): "; cin >> month2 >> day2 >> year2; } juliandate = cout << month << day << year << endl; cout << month2 << day2 << year2 << endl; cout << "# of days between these dates is: " << numofdays; }
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <math.h> #include <stdlib.h>
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.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
Join Date: Feb 2007
Posts: 8
Reputation:
Solved Threads: 0
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:
or for leap year:
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
Code i am using is C++
Last night was finally able to get the julian date formula from my instructor is it as follows:
C++ Syntax (Toggle Plain Text)
jdate = year - 1900; jdate = year * 365 +((year-1)/4) + DaysInYear[month] + day
or for leap year:
C++ Syntax (Toggle Plain Text)
jdate = year - 1900; 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
![]() |
Similar Threads
- java program to calculate simple interest (Java)
- Emergency.....easy Program Week Days (Java)
- Logic to Convert Days From 1800 to a Date (Month, Day, Year) (C++)
- Simple Time/Date Program (C)
Other Threads in the C++ Forum
- Previous Thread: Problem kicking my but!!! can anybody help?
- Next Thread: Calculator project
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib library list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings struct temperature template templates text tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






