fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. unsigned difference_in_minutes(unsigned, unsigned);
  6.  
  7. int main()
  8. {
  9. unsigned start, end;
  10.  
  11. // cout << "Please input your start time in military time(example: 8:3=2030): ";
  12. cin >> start;
  13.  
  14. // cout << "Please input your end time: ";
  15. cin >> end;
  16.  
  17. cout << "Your elapsed time is " << difference_in_minutes(start, end) << " minutes.";
  18.  
  19. return 0;
  20. }
  21.  
  22. unsigned minutes_since_midnight(unsigned military_time)
  23. {
  24. const unsigned hours = military_time / 100;
  25. const unsigned minutes = military_time % 100;
  26.  
  27. return hours * 60 + minutes;
  28. }
  29.  
  30. unsigned difference_in_minutes(unsigned begin_time, unsigned end_time)
  31. {
  32. const unsigned beg = minutes_since_midnight(begin_time);
  33. const unsigned end = minutes_since_midnight(end_time);
  34.  
  35. return end - beg;
  36. }
Success #stdin #stdout 0s 3300KB
stdin
1144
1215
stdout
Your elapsed time is 31 minutes.