Thread: Modulo operator
View Single Post
  #1  
Old 10-17-2010, 10:52 AM
TheDon's Avatar
TheDon TheDon is offline
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