PeachParts Mercedes-Benz Forum

PeachParts Mercedes-Benz Forum (http://www.peachparts.com/shopforum/index.php)
-   Off-Topic Discussion (http://www.peachparts.com/shopforum/forumdisplay.php?f=16)
-   -   Modulo operator (http://www.peachparts.com/shopforum/showthread.php?t=286674)

TheDon 10-17-2010 09:52 AM

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)

Matt L 10-17-2010 09:55 AM

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.

TheDon 10-17-2010 10:08 AM

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

Matt L 10-17-2010 10:12 AM

You're on the right track.

Have you learned to use the debugger?

TheDon 10-17-2010 10:13 AM

nice... I'm afraid of that modulo operator since I've never used it.

now to just implement what I am thinking into C

Matt L 10-17-2010 10:18 AM

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++.

TheDon 10-17-2010 10:19 AM

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

Matt L 10-17-2010 10:20 AM

You'll find that last part a bit difficult.


All times are GMT -4. The time now is 09:06 PM.

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