Guest User

Untitled

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