CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

mm:ss:dd subtraction ?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








mm:ss:dd subtraction ?
PostPosted: Tue Aug 30, 2005 1:31 am     Reply with quote

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

View user's profile Send private message Send e-mail Yahoo Messenger

Re: mm:ss:dd subtraction ?
PostPosted: Tue Aug 30, 2005 5:56 am     Reply with quote

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








PostPosted: Tue Aug 30, 2005 6:11 am     Reply with quote

thanks very much!
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Aug 30, 2005 6:16 am     Reply with quote

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!
    }
  }
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group