Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using std::cin;
- using std::cout;
- using std::endl;
- int DateDifference(void);
- void ProcessDifference(int difference);
- int main(void)
- {
- int difference = DateDifference();
- ProcessDifference(difference);
- return 0;
- }
- int DateDifference(void)
- {
- int firstDateDay;
- cout << "Enter day of your first date: ";
- cin >> firstDateDay;
- int firstDateMonth;
- cout << "Enter month of your first date: ";
- cin >> firstDateMonth;
- int firstDateHours;
- cout << "Enter hours of your first date: ";
- cin >> firstDateHours;
- int firstDateMinutes;
- cout << "Enter minutes of your first date: ";
- cin >> firstDateMinutes;
- cout << firstDateDay << "." << firstDateMonth << " " << firstDateHours << ":" << firstDateMinutes << endl;
- int secondDateDay;
- cout << "Enter day of your second date: ";
- cin >> secondDateDay;
- int secondDateMonth;
- cout << "Enter month of your second date: ";
- cin >> secondDateMonth;
- int secondDateHours;
- cout << "Enter hours of your second date: ";
- cin >> secondDateHours;
- int secondDateMinutes;
- cout << "Enter minutes of your second date: ";
- cin >> secondDateMinutes;
- cout << secondDateDay << "." << secondDateMonth << " " << secondDateHours << ":" << secondDateMinutes << endl;
- int firstDateGeneralTime = (firstDateMonth - 1) * 43200 + (firstDateDay - 1) * 1440 + firstDateHours * 60 + firstDateMinutes;
- int secondDateGeneralTime = (secondDateMonth - 1) * 43200 + (secondDateDay - 1) * 1440 + secondDateHours * 60 + secondDateMinutes;
- return firstDateGeneralTime > secondDateGeneralTime ? firstDateGeneralTime - secondDateGeneralTime : secondDateGeneralTime - firstDateGeneralTime;
- }
- void ProcessDifference(int difference)
- {
- cout << "Difference: " << difference << " minutes." << endl;
- int months = difference / 43200;
- difference -= months * 43200;
- int days = difference / 1440;
- difference -= days * 1440;
- int hours = difference / 60;
- difference -= hours * 60;
- int minutes = difference;
- cout << "Diffrence: " << months << " months, " << days << " days, " << hours << " hours, " << minutes << " minutes.";
- }
Advertisement
Add Comment
Please, Sign In to add comment