Write a C++ program that prompts the user to input the elapsed time for an event in hours, minutes, and seconds.
The program then outputs the elapsed time in seconds.
Code:
#include <iostream>
using namespace std;
int main()
{
int hours, min, sec, totalsec;
const int secPerMin = 60;
const int secPerHour = 60 * secPerMin;
cout << "Please input the hours: ";
cin >> hours;
cout << "Please input the minutes: ";
cin >> min;
cout << "Please input the seconds: ";
cin >> sec;
totalsec = sec + (min * secPerMin) + (hours * secPerHour);
cout << "That equals a total of " << totalsec << " seconds." << endl;
return 0;
}