garryhtreez

6.25

Dec 10th, 2020
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. /* 6.25 Calculating Number of Minutes
  2.    Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
  3.    Visual Studio Community 2019
  4. */
  5.  
  6. #include <iostream>
  7. #include <cstdlib>
  8. using namespace std;
  9.  
  10. int minutesSinceStartofMonth(int days, int hours, int minutes) {
  11.     int minutesSinceStart{ 0 };
  12.     // value for days is actually (days - 1) FULL days where hours and minutes make up the PARTIAL day
  13.     minutesSinceStart = (days-1) * 24 * 60 + hours * 60 + minutes;
  14.     return minutesSinceStart;
  15. }
  16.  
  17. int main(void) {
  18.     int days1, days2, hours1, hours2, minutes1, minutes2, total1, total2, difference;
  19.     cout << "Enter the day of the month for 1st day in question: ";
  20.     cin >> days1;
  21.     cout << "Enter number of hours of this day: ";
  22.     cin >> hours1;
  23.     cout << "Enter number of minutes of this day: ";
  24.     cin >> minutes1;
  25.     cout << "Enter the day of the month for 2nd day in question: ";
  26.     cin >> days2;
  27.     cout << "Enter number of hours of this day: ";
  28.     cin >> hours2;
  29.     cout << "Enter number of minutes of this day: ";
  30.     cin >> minutes2;
  31.  
  32.     total1 = minutesSinceStartofMonth(days1, hours1, minutes1);
  33.     total2 = minutesSinceStartofMonth(days2, hours2, minutes2);
  34.     difference = abs(total1 - total2);
  35.     cout << "The difference between the two dates is: " << difference << " minutes" << endl;
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment