Parts Catalog Accessories Catalog How To Articles Tech Forums
Call Pelican Parts at 888-280-7799
Shopping Cart Cart | Project List | Order Status | Help



Go Back   PeachParts Mercedes-Benz Forum > General Discussions > Off-Topic Discussion

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 10-17-2010, 09:52 AM
TheDon's Avatar
Ghost of Diesels Past
 
Join Date: Oct 2005
Posts: 13,285
Modulo operator

The fifth operation many of us didn't learn. I know I didn't since I really don't know how to use it.


this following discussion will center around C programming language

I'm trying to get the minutes and seconds from a positive integer that its value is the time in seconds.

example 500 seconds.

the result is then added to 1:00:00 pm

so I need to get the minutes and seconds. Then determine if the minutes are greater than 60 I'll have to determine the hours and then minutes and seconds again. (which can probably be done recursively)

another example is 7128 seconds.




my work so far, well thinking. with 500 seconds

(for this example I did not declare a variable for the 500 seconds, but it will be done)

int minutes = 500/60 =8.333333 minutes. Floor the number

int seconds = 500 %(mod) 60 = 20 seconds.

I would then add the minutes and seconds to 1:00:00 pm. Still trying to figure out how I plan on doing this but I have to use a struct(working with stacks and queues) so I might make the in time always 1:00:00 and the out time also (1:00:00+work above)+(an equation for something else within my program)

Reply With Quote
  #2  
Old 10-17-2010, 09:55 AM
Registered User
 
Join Date: Oct 2005
Posts: 4,263
Was there a question in there somewhere?

Note that in C, 500/60 is 8. No need for floor, as it is an integer operation. This can and does bite you with negative numbers, so be careful what you ask the compiler to do.
Reply With Quote
  #3  
Old 10-17-2010, 10:08 AM
TheDon's Avatar
Ghost of Diesels Past
 
Join Date: Oct 2005
Posts: 13,285
yeah, forgot that I don't have to worry about the decimal places with an int. All numbers I have will be positive ints.



I should have said I want to know if I am doing what I think I need to be doing correctly
Reply With Quote
  #4  
Old 10-17-2010, 10:12 AM
Registered User
 
Join Date: Oct 2005
Posts: 4,263
You're on the right track.

Have you learned to use the debugger?
Reply With Quote
  #5  
Old 10-17-2010, 10:13 AM
TheDon's Avatar
Ghost of Diesels Past
 
Join Date: Oct 2005
Posts: 13,285
nice... I'm afraid of that modulo operator since I've never used it.

now to just implement what I am thinking into C
Reply With Quote
  #6  
Old 10-17-2010, 10:18 AM
Registered User
 
Join Date: Oct 2005
Posts: 4,263
C is an easy language. Except when it's not. There's a wide class of innocent-looking code that results in undefined behavior.

Post what you have so far. I like reading code, although I'm not quite as good at that as a compiler.

I have done a lot of work in C, and still do occasionally, but work much more in C++ these days. C is a very clean language compared to C++.
Reply With Quote
  #7  
Old 10-17-2010, 10:19 AM
TheDon's Avatar
Ghost of Diesels Past
 
Join Date: Oct 2005
Posts: 13,285
I havent gotten to that point yet. I was just figuring out how to approach the seconds to make it into the format I need.

when that happens I'll pm you
Reply With Quote
  #8  
Old 10-17-2010, 10:20 AM
Registered User
 
Join Date: Oct 2005
Posts: 4,263
You'll find that last part a bit difficult.

Reply With Quote
Reply

Bookmarks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:24 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0
Copyright 2024 Pelican Parts, LLC - Posts may be archived for display on the Peach Parts or Pelican Parts Website -    DMCA Registered Agent Contact Page