// program to output the difference between two input times #include #include int main() { int count(0); int firsttotal(0); int secondtotal(0); try{ do{ int hours(0); int min(0); int sec(0); int total(0); std::cout << "Please input hours, minutes, seconds:" << '\n'; std::cin >> hours >> min >> sec; if(not std::cin) throw std::exception(); if(hours >= 1) total += hours * 3600; if(min >= 1) total += min * 60; if(sec >= 1) total += sec; ++count; if(count == 1) firsttotal = total; if(count > 1) secondtotal = total; }while(count < 2); int biggest(0); int smallest(0); if(firsttotal > secondtotal) { biggest = firsttotal; smallest = secondtotal; } else { biggest = secondtotal; smallest = firsttotal; } int seconds(0); seconds = biggest-smallest; int hours(0); int mins(0); hours = seconds / 3600; int h_sec(0); h_sec = hours * 3600; seconds-= h_sec; mins = seconds / 60; int m_sec(0); m_sec = mins * 60; seconds-= m_sec; std::cout << "The time difference is " << hours << " hours, " << mins << " minutes, " << seconds << " seconds.\n"; } catch(...) { std::cerr << "***An exception was thrown***\n"; } }