// // Program: secondsToHMS. // // Purpose: Convert seconds to hours, minutes, seconds. // (Also, illustrate pass-by-reference parameters.) // // Input: number of seconds N (non-negative integer). // Output: hours, minutes, and seconds in N. // #include #include // has EXIT_SUCCESS, EXIT_FAILURE // Pre: N >= 0. // Post: S seconds, M minutes, H hours = N seconds. void secondsToHMS(int N, int & H, int & M, int & S) { H = N / (60*60); M = (N / 60) % 60; S = N % 60; return; } // Main program. int main(void) { int sec; int hh, mm, ss; cout << "Enter a non-negative number of seconds:\n"; cin >> sec; if (sec < 0) { cout << "Error: Number must be non-negative.\n"; exit(EXIT_FAILURE); } secondsToHMS(sec, hh, mm, ss); cout << sec << " seconds = " << hh << " hours, " << mm << " minutes, " << ss << " seconds.\n"; return EXIT_SUCCESS; }