Write a program in C++ that create a function named time. The time function receives number of
seconds as parameter and returns time as string in the following format: H:M:S.
For example, if seconds are 25412 then function should display
Time = 7:3:32
my attempt i am stuck and couldnt solve this return time as string has confused me
#include <iostream>
#include<string>
using namespace std;
string CLOCK(int seconds, int minutes,int hours);
int main()
{
int hours;
int minutes;
int seconds;
int time = 0;
cout << "Enter time elapsed, in seconds: ";
cin >> time;
cout << endl;
cout<<"Time is : "<<CLOCK(time,seconds,minutes,hours);
return 0;
}
string CLOCK(int seconds, int minutes,int hours)
{
int time=0
int hours;
int minutes;
int seconds;
string str1=":0"
string str2=":"
hours = static_cast<int>(time / 3600);
time = time - hours * 3600;
minutes = static_cast<int>(time / 60);
time = time - minutes * 60;
seconds = time;
return (hours)
if (minutes < 10)
return(":0" minutes)
else
return( ":" minutes)
if (seconds < 10)
return(":0" seconds)
else
return(":"seconds)
}
Runnable link:http://code.runnable.com/me/Vx9p-GbTq1UJNvbQ