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.
Display:
Enter the hours: 2
Enter the minutes: 40
Enter the seconds: 30
The elapsed time in seconds is: 9630.
End of Program
Code:
#include
using namespace std;
int main ()
{
//declaration of variables
int seconds, minutes, hours, elapsedtime;
//Prompt the user for input
cout << "Enter the hours: ";
cin >> hours;
cout << "Enter the minutes: ";
cin >> minutes;
cout << "Enter the seconds: ";
cin >> seconds;
//Calculation
elapsedtime = (hours * 3600) + (minutes * 60) + seconds;
//Display output
cout << "The elapsed time in seconds is: " << elapsedtime << ".";
//closing
cout << "\nEnd of Program\n\n";
return 0;
}