954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C++ Assist

Can someone offer assistance in converting seconds to minutes and seconds. :?:

111Help
Newbie Poster
3 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

Divide by 60 and multiply by 60. Nothing to it.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Thanks. I intended to include that I have the total number of minutes 46 and seconds as 6 time used on a 80 minute CD. I know that 33 minutes and 54 seconds is the remainder I am trying to figure out how to put it in C++ form. And maybe I am making too much of this.

Thanks

111Help
Newbie Poster
3 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

Do you mean something like this:

struct Time
{
   int minutes;
   int seconds;
   friend ostream & operator<<(ostream & os, const Time & t)
   {
      os << t.minutes << " minutes and " << t.seconds << " seconds" << endl;
   }
}

Time timeUsed;
Time timeRemaining;

timeUsed.minutes = 46;
timeUsed.seconds = 6;

timeRemaining.minutes = 33;
timeRemaining.seconds = 54;

std::cout << timeUsed << std::endl;
std::cout << timeRemaining << std::endl;
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

Thanks, was trying to do an actual calculation to obtain it:

cdminutes = 80 - totimemin;
cdseconds = 60 - totimesec;


I truly thanks you, trying to make something simple, difficult. GOD bless....thanks I will take a break from it and go back....

111Help
Newbie Poster
3 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

Method A:
Convert all times to seconds.
Subtract one time from another to get remaining time.
Then convert remaining time back to minutes and seconds.

Method B:
Overload the - operator for a Time class similar to one I previously wrote.
Time objects have a minutes member and a seconds member
Assume you want to subtract Time B from Time A and store result in Time C.

within body of - operator code declare a Time object called temp

if(B.seconds > A.seconds)
then A.seconds += 60;
and A.minutes -= 1;

temp.minutes = A.minutes - B.minutes
temp.seconds = A.seconds - B.seconds

return temp

Example of use:
Time A, B, C;
A.minutes = 80
A.seconds = 0
B.minutes = 46
B.seconds = 6

C = A - B;


There are other methods as well, depending your knowledge base, etc.

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You