Divide by 60 and multiply by 60. Nothing to it.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
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
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