Guest User

Untitled

a guest
Nov 7th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1. #include <iostream>
  2. using std::cin;
  3. using std::cout;
  4. using std::endl;
  5. int DateDifference(void);
  6. void ProcessDifference(int difference);
  7. int main(void)
  8. {
  9.     int difference = DateDifference();
  10.     ProcessDifference(difference);
  11.     return 0;
  12. }
  13.  
  14. int DateDifference(void)
  15. {
  16.     int firstDateDay;
  17.     cout << "Enter day of your first date: ";
  18.     cin >> firstDateDay;
  19.     int firstDateMonth;
  20.     cout << "Enter month of your first date: ";
  21.     cin >> firstDateMonth;
  22.     int firstDateHours;
  23.     cout << "Enter hours of your first date: ";
  24.     cin >> firstDateHours;
  25.     int firstDateMinutes;
  26.     cout << "Enter minutes of your first date: ";
  27.     cin >> firstDateMinutes;
  28.     cout << firstDateDay << "." << firstDateMonth << " " << firstDateHours << ":" << firstDateMinutes << endl;
  29.     int secondDateDay;
  30.     cout << "Enter day of your second date: ";
  31.     cin >> secondDateDay;
  32.     int secondDateMonth;
  33.     cout << "Enter month of your second date: ";
  34.     cin >> secondDateMonth;
  35.     int secondDateHours;
  36.     cout << "Enter hours of your second date: ";
  37.     cin >> secondDateHours;
  38.     int secondDateMinutes;
  39.     cout << "Enter minutes of your second date: ";
  40.     cin >> secondDateMinutes;
  41.     cout << secondDateDay << "." << secondDateMonth << " " << secondDateHours << ":" << secondDateMinutes << endl;
  42.     int firstDateGeneralTime = (firstDateMonth - 1) * 43200 + (firstDateDay - 1) * 1440 + firstDateHours * 60 + firstDateMinutes;
  43.     int secondDateGeneralTime = (secondDateMonth - 1) * 43200 + (secondDateDay - 1) * 1440 + secondDateHours * 60 + secondDateMinutes;
  44.     return firstDateGeneralTime > secondDateGeneralTime ? firstDateGeneralTime - secondDateGeneralTime : secondDateGeneralTime - firstDateGeneralTime;
  45. }
  46.  
  47. void ProcessDifference(int difference)
  48. {
  49.     cout << "Difference: " << difference << " minutes." << endl;
  50.     int months = difference / 43200;
  51.     difference -= months * 43200;
  52.     int days = difference / 1440;
  53.     difference -= days * 1440;
  54.     int hours = difference / 60;
  55.     difference -= hours * 60;
  56.     int minutes = difference;
  57.     cout << "Diffrence: " << months << " months, " << days << " days, " << hours << " hours, " << minutes << " minutes.";
  58. }
Advertisement
Add Comment
Please, Sign In to add comment