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);
- int main(void)
- {
- int difference = DateDifference();
- cout << "Diffrence: " << difference;
- }
- int DateDifference(void)
- {
- int firstDateMonth;
- cout << "Enter month of your first date: ";
- cin >> firstDateMonth;
- int firstDateDay;
- cout << "Enter day of your first date: ";
- cin >> firstDateDay;
- 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 secondDateMonth;
- cout << "Enter month of your second date: ";
- cin >> secondDateMonth;
- int secondDateDay;
- cout << "Enter day of your second date: ";
- cin >> secondDateDay;
- 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;
- if (firstDateMonth == 1)
- firstDateGeneralTime = firstDateDay * 24 * 60 + firstDateHours * 60 + firstDateMinutes;
- else
- firstDateGeneralTime = firstDateMonth * 30 * 24 * 60 + firstDateDay * 24 * 60 + firstDateHours * 60 + firstDateMinutes;
- int secondDateGeneralTime;
- if (secondDateMonth == 1)
- secondDateGeneralTime = secondDateDay * 24 * 60 + secondDateHours * 60 + secondDateMinutes;
- else
- secondDateGeneralTime = secondDateMonth * 30 * 24 * 60 + secondDateDay * 24 * 60 + secondDateHours * 60 + secondDateMinutes;
- return firstDateGeneralTime > secondDateGeneralTime ? firstDateGeneralTime - secondDateGeneralTime : secondDateGeneralTime - firstDateGeneralTime;
- }
Advertisement
Add Comment
Please, Sign In to add comment