Program should continually have user enter a positive integer, and quits on zero entered. This entered number represents the total number of seconds and after each number is entered a function is called that displays the time in hours, minutes and seconds. Sample output is as follows:
Enter Total Seconds --> 3605
1:00:05
The function needs only one value parameter and should return nothing back to main. If the minutes or seconds are a one digit number then make sure to display a leading zero as the example above shows.
Here is my program. my question is how do i make the numbers appear like this?
1:00:05
#include <iostream>
#include <iomanip>
usingnamespace std;
int ClockTime (int H, int M, int S);
int main();
{
int Seconds, Minutes, Hours;
do {
cout << "Enter total seconds --> ";
cin >> Seconds;
Minutes = Seconds / 60;
Hours = Minutes / 60;
ClockTime ();
}
while (Seconds != 0);
}
int ClockTime (int H, int M, int S)
{
cout << H << ":" << M << ":" << S;
}
#include <iostream>
#include <iomanip>
usingnamespace std;
// function that displays the time in hours, minutes and seconds
// The function needs only one value parameter and should return nothing back to main
void print_time( int seconds ) ;
int main()
{
int seconds;
do {
cout << "Enter total seconds --> ";
cin >> seconds ;
// after each number is entered the function is called.
if( seconds > 0 ) print_time(seconds) ;
}
while( seconds != 0 );
}
void print_time( int seconds )
{
constint hours = ( seconds / 3600 ) % 24 ;
constint minutes = ( seconds / 60 ) % 60 ;
seconds = seconds % 60;
cout << hours << ":" << setw(2) << setfill('0') << minutes << ":"
<< setw(2) << setfill('0') << seconds << '\n' ;
}