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

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

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.


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;

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....

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.