Computer Science Canada

Rounding minutes

Author:  BiggZigg9 [ Thu Jan 20, 2011 9:21 am ]
Post subject:  Rounding minutes

Hey can anyone help,
So i have to do this short turing activity which involves calculating the cost of a long distance call. My problem is i dont know how to make it so that 1 sec = 1 min, 61 sec = 2 mins ect. HELP please

Thanks

Author:  2goto1 [ Thu Jan 20, 2011 9:55 am ]
Post subject:  RE:Rounding minutes

The modulus operator might be your friend here

Author:  Zren [ Thu Jan 20, 2011 10:06 am ]
Post subject:  RE:Rounding minutes

ceil() is the function your looking for. Also it's opposite function is floor() is case you were wondering.

Edit: Also I think 2goto1 meant using Integer division. Added to the example.

Eg:
Turing:

View.Set ("offscreenonly")
var t : int
var seconds : real
loop
    cls
    t := Time.ElapsedCPU
    seconds := t / 1000
    put "Miliseconds: ", t
    put "Seconds: ", seconds
    put "Ceil: ", ceil (seconds), " seconds"
    put "Floor: ", floor (seconds), " seconds"
    put skip
    put "Integer Division: ", t div (1000), " seconds"
    View.Update
end loop

Author:  BiggZigg9 [ Thu Jan 20, 2011 12:50 pm ]
Post subject:  RE:Rounding minutes

no like i need to make it so that when the person puts in eg) 61 seconds the program beconizes it as 2 mins?

Author:  Tony [ Thu Jan 20, 2011 12:52 pm ]
Post subject:  RE:Rounding minutes

Yes, you are looking for ceil type rounding.

Author:  BiggZigg9 [ Thu Jan 20, 2011 12:54 pm ]
Post subject:  RE:Rounding minutes

okay well i am a huge noob at turing so haha.......

Author:  2goto1 [ Thu Jan 20, 2011 12:58 pm ]
Post subject:  RE:Rounding minutes

yah ceiling better than modulus in this case

Author:  Insectoid [ Thu Jan 20, 2011 4:14 pm ]
Post subject:  RE:Rounding minutes

This is a common problem called the Pigeonhole Principle. It pops up all over the place, so learn it and remember it.

Author:  Tony [ Thu Jan 20, 2011 4:22 pm ]
Post subject:  RE:Rounding minutes

Pigeonhole Principle is a construct used in many proofs, not really "a problem". I don't follow how this is applicable to mod/ceil


: