11 Years
Discussion Span
Last Post by Lerner

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.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.