Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cassert>
- using namespace std;
- int julianDateCalc(int x, int y);
- int daysPerMonth[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
- int main()
- {
- int firstDay, secondDay, firstMonth, secondMonth = 0;
- //Read in dates by the user.
- cout << "Please enter two dates in number format (dd mm)" << endl;
- cout << "Day: ";
- cin >> firstDay;
- cout << "Month: ";
- cin >> firstMonth;
- cout << endl;
- cout << "Day: ";
- cin >> secondDay;
- cout << "Month: ";
- cin >> secondMonth;
- cout << endl;
- //Check validity of date entered.
- assert(firstDay > 0 && firstDay < (daysPerMonth[firstMonth - 1] + 1));
- assert(secondDay > 0 && secondDay < (daysPerMonth[secondMonth - 1] + 1));
- //Function calls for the Julian conversion.
- julianDateCalc(firstDay, firstMonth);
- julianDateCalc(secondDay, secondMonth);
- //Check to determine which date is lower/higher and calculate difference in days between the dates.
- if (julianDateCalc(firstDay, firstMonth) > julianDateCalc(secondDay, secondMonth))
- {
- cout << "The first date converted is: " << julianDateCalc(firstDay, firstMonth) << endl;
- cout << "The second date converted is: " << julianDateCalc(secondDay, secondMonth) << endl;
- cout << endl;
- cout << " The difference in days between the two dates is: " << julianDateCalc(firstDay, firstMonth) - julianDateCalc(secondDay, secondMonth) << " days" << endl;
- }
- else
- {
- cout << "The first date converted is: " << julianDateCalc(firstDay, firstMonth) << endl;
- cout << "The second date converted is: " << julianDateCalc(secondDay, secondMonth) << endl;
- cout << endl;
- cout << "The difference in days between the two dates is: " << julianDateCalc(secondDay, secondMonth) - julianDateCalc(firstDay, firstMonth) << " days" << endl;
- }
- return 0;
- }
- //Function to calculate the Julian date of the user's entry.
- int julianDateCalc(int day, int month)
- {
- int sum = 0;
- for (int i = 0; i < month - 1 ; i++)
- {
- sum += daysPerMonth[i];
- }
- return sum + day;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement