Author |
Message |
BiggZigg9
|
Posted: 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 |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
2goto1

|
Posted: Thu Jan 20, 2011 9:55 am Post subject: RE:Rounding minutes |
|
|
The modulus operator might be your friend here |
|
|
|
|
 |
Zren

|
Posted: 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
|
|
|
|
|
|
 |
BiggZigg9
|
Posted: 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? |
|
|
|
|
 |
Tony

|
|
|
|
 |
BiggZigg9
|
Posted: Thu Jan 20, 2011 12:54 pm Post subject: RE:Rounding minutes |
|
|
okay well i am a huge noob at turing so haha....... |
|
|
|
|
 |
2goto1

|
Posted: Thu Jan 20, 2011 12:58 pm Post subject: RE:Rounding minutes |
|
|
yah ceiling better than modulus in this case |
|
|
|
|
 |
Insectoid

|
Posted: 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. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tony

|
Posted: 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 |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
|