Mature_Student 0 Newbie Poster

Thanks a bunch!

I will give it a try.

Mature_Student 0 Newbie Poster

Thanks Dave! I got the formatting part. and it produces the format I rquire but I still do not have the output in the formattedTime string.

if I put anything infront of the << operator I get plenty of errors.

int hr, min, sec;
	string formattedTime;

	hr = ts / 360;
	ts = ts % 360;
	min = ts / 60;
	sec = ts % 60;

	//Formatted Time 
	 formattedTime<< setw(2) << setfill('0') << hr <<":" << setw(2) << setfill('0') << min <<":"<< setw(2) << setfill('0') << sec;

	return (formattedTime);

Thanks for all this, I really appreciate the help.

Mature_Student 0 Newbie Poster

Then I really don't get it.

I tried ToString, itoi, itol

These are commands that I got searching the web. none of these were taught in class. Hence my problem with this assignment.

If anyone can give me the command I should use and its syntax, I should be able to figure it out.

Mature_Student 0 Newbie Poster

I have a user inputted number of seconds : 421

I need to output the string 01:01:01

I can break out the integer 421 into 1 hr 1 min and 1 sec no problem, but I cannot seem to get it together in the form hh:mm:ss

I would like to use sprintf but have no idea how to syntax it for my problem.

shr = sprintf(hr);

gives me an "no overloaded function takes 1 arguments" I don't know what that means other than that I am not using the command properly.

Thanks for all the help guys, I need it.

Mature_Student 0 Newbie Poster

Shouldn't it look more like this, then?

string FormatTime(int ts)
{
   string result;
   // ...
   return result;
}

And used like this?

string formattedTime = FormatTime(totalSeconds);

Ok I have renamed the function but I still cannot see how to get the separate elements (hr, min, sec) into formattedTime with zero padding.

....

	string formattedTime = FormatTime(totalSeconds);

	cout << "\n\nThe time in seconds you entered ("<< totalSeconds << " seconds) is equivelant to " << formattedTime;
	cout <<"\n\nThank you for using the time converter\n\n";

	return 0;
}
string FormatTime(int ts)
{
	int hr, min, sec;
	string formattedTime

	hr = ts / 360;
	ts = ts % 360;
	min = ts / 60;
	sec = ts % 60;

// formattedTime = [I]created string here[/I]

	return (formattedTime);
}

I have taken the total seconds separated them, and now need to put it back together.

Sorry if I am still confused.

Mature_Student 0 Newbie Poster

Hi there, I have used the advice in this forum to solve most of the problems I have had so far but I am running out of time on this final assignment (due this evening) and I am stumped.

I need to write a function that takes a time in seconds and returns a formatted string (hh:mm:ss)

I am specifically not permitted to use an array (not that I know how to use one yet)

My code looks like this right now. I can easily obtain the components of the string in integer formatbut I cannot figure out how to pass them to the string with zero padding et al..

Help would be greatly appreciated.

#include <iostream>
#include <iomanip>

using namespace std;

int FormatTime(int ts, string formatted time);

int main ()
{
	int totalSeconds;
	string formattedTime;
	
	cout << "*********************************************************\n";
	cout << "*\tWelcome to the Time Re-format application\t*\n";
	cout << "*********************************************************\n\n\n";

	cout << "Please enter a time in seconds and press <Enter>: ";
	cin >> totalSeconds;
	
	FormatTime(totalSeconds, formattedTime);

	cout << "\n\nThe time in seconds you entered ("<< totalSeconds << " seconds) is equivelant to " << formattedTime;
	cout <<"\n\nThank you for using the time converter\n\n";

	return 0;
}
int FormatTime(int ts, string formattedTime)
{
	int hr, min, sec;

	hr = ts / 360;
	ts = ts % 360;
	min = ts / 60;
	sec = ts % 60;

	return (formattedTime);
}