
-----------------------------------
BiggZigg9
Thu Jan 20, 2011 9:21 am

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

-----------------------------------
2goto1
Thu Jan 20, 2011 9:55 am

RE:Rounding minutes
-----------------------------------
The modulus operator might be your friend here

-----------------------------------
Zren
Thu Jan 20, 2011 10:06 am

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:

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


-----------------------------------
BiggZigg9
Thu Jan 20, 2011 12:50 pm

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?

-----------------------------------
Tony
Thu Jan 20, 2011 12:52 pm

RE:Rounding minutes
-----------------------------------
Yes, you are looking for [tdoc]ceil[/tdoc] type rounding.

-----------------------------------
BiggZigg9
Thu Jan 20, 2011 12:54 pm

RE:Rounding minutes
-----------------------------------
okay well i am a huge noob at turing so haha.......

-----------------------------------
2goto1
Thu Jan 20, 2011 12:58 pm

RE:Rounding minutes
-----------------------------------
yah ceiling better than modulus in this case

-----------------------------------
Insectoid
Thu Jan 20, 2011 4:14 pm

RE:Rounding minutes
-----------------------------------
This is a common problem called the [url=http://en.wikipedia.org/wiki/Pigeonhole_principle]Pigeonhole Principle. It pops up all over the place, so learn it and remember it.

-----------------------------------
Tony
Thu Jan 20, 2011 4:22 pm

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
