View previous topic :: View next topic |
Author |
Message |
Guest
|
mm:ss:dd subtraction ? |
Posted: Tue Aug 30, 2005 1:31 am |
|
|
I have a number of mm:ss:dd where mm is minutes, ss is second and dd is tenth of second, my problem is subtraction to 8? that is es:
01:32:01 - 00:00:08 = xx:xx:xx
02:01:05 - 00:00:08 = xx:xx:xx
............ - 00:00:08 = xx:xx:xx
As I can make subtraction? |
|
|
MikeValencia
Joined: 04 Aug 2004 Posts: 238 Location: Chicago
|
Re: mm:ss:dd subtraction ? |
Posted: Tue Aug 30, 2005 5:56 am |
|
|
Anonymous wrote: | I have a number of mm:ss:dd where mm is minutes, ss is second and dd is tenth of second, my problem is subtraction to 8? that is es:
01:32:01 - 00:00:08 = xx:xx:xx
02:01:05 - 00:00:08 = xx:xx:xx
............ - 00:00:08 = xx:xx:xx
As I can make subtraction? |
Make the following math operation:
((1 * 60 * 60) + (32 * 60) + 1) - 8
This will give you the number of seconds (a very big number)
Then convert the big number back to hh:mm:ss
Think first of the math on how you would do it. Then write the corresponding source code. |
|
|
Guest
|
|
Posted: Tue Aug 30, 2005 6:11 am |
|
|
thanks very much! |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Aug 30, 2005 6:16 am |
|
|
From math class:
Code: |
signed int8 minutes, seconds, tenths;
// Init some values
minutes = 1;
seconds = 32;
tenths = 1;
// Subtract the 8
tenths -= 8;
// See if we need to borrow 1
if (tenths < 0)
{
// We did so add 1 or 10 tenths
tenths += 10;
// Borrow it
seconds--;
// Do we need to borrow a minute?
if (seconds < 0)
{
// Yep, so do it
seconds += 60;
minutes--;
// Maybe you want to check for negative here!
}
} |
|
|
|
|