Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 6.25 Calculating Number of Minutes
- Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
- Visual Studio Community 2019
- */
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int minutesSinceStartofMonth(int days, int hours, int minutes) {
- int minutesSinceStart{ 0 };
- // value for days is actually (days - 1) FULL days where hours and minutes make up the PARTIAL day
- minutesSinceStart = (days-1) * 24 * 60 + hours * 60 + minutes;
- return minutesSinceStart;
- }
- int main(void) {
- int days1, days2, hours1, hours2, minutes1, minutes2, total1, total2, difference;
- cout << "Enter the day of the month for 1st day in question: ";
- cin >> days1;
- cout << "Enter number of hours of this day: ";
- cin >> hours1;
- cout << "Enter number of minutes of this day: ";
- cin >> minutes1;
- cout << "Enter the day of the month for 2nd day in question: ";
- cin >> days2;
- cout << "Enter number of hours of this day: ";
- cin >> hours2;
- cout << "Enter number of minutes of this day: ";
- cin >> minutes2;
- total1 = minutesSinceStartofMonth(days1, hours1, minutes1);
- total2 = minutesSinceStartofMonth(days2, hours2, minutes2);
- difference = abs(total1 - total2);
- cout << "The difference between the two dates is: " << difference << " minutes" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment