|
|
|
#1
|
||||
|
||||
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) |
#2
|
|||
|
|||
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. |
#3
|
||||
|
||||
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 |
#4
|
|||
|
|||
You're on the right track.
Have you learned to use the debugger? |
#5
|
||||
|
||||
nice... I'm afraid of that modulo operator since I've never used it.
now to just implement what I am thinking into C |
#6
|
|||
|
|||
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++. |
#7
|
||||
|
||||
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 |
#8
|
|||
|
|||
You'll find that last part a bit difficult.
|
Bookmarks |
|
|