Advertisement
jasonpogi1669

Find the Total Minutes between 2 Time Given in 24-hour Format using C++

Oct 13th, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     string time1, time2;
  7.     cin >> time1 >> time2;
  8.     double x_hours = stoi(time1.substr(0, 2));
  9.     double x_mins = stoi(time1.substr(3, 2));
  10.     double y_hours = stoi(time2.substr(0, 2));
  11.     double y_mins = stoi(time2.substr(3, 2));
  12.     double minutes_between = (60 - y_mins) + (60 * (x_hours - (y_hours + 1))) + x_mins;
  13.     cout << minutes_between << " minutes" << endl;
  14.     return 0;
  15. }
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement