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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
2goto1
![](http://compsci.ca/v3/uploads/user_avatars/787605484d25cfd31b548.jpg)
|
Posted: Thu Jan 20, 2011 9:55 am Post subject: RE:Rounding minutes |
|
|
The modulus operator might be your friend here |
|
|
|
|
![](images/spacer.gif) |
Zren
![](http://compsci.ca/v3/uploads/user_avatars/1110053965512db6185954b.png)
|
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
|
|
|
|
|
|
![](images/spacer.gif) |
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? |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
|
|
|
![](images/spacer.gif) |
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....... |
|
|
|
|
![](images/spacer.gif) |
2goto1
![](http://compsci.ca/v3/uploads/user_avatars/787605484d25cfd31b548.jpg)
|
Posted: Thu Jan 20, 2011 12:58 pm Post subject: RE:Rounding minutes |
|
|
yah ceiling better than modulus in this case |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
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. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
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. |
|
|
|
![](images/spacer.gif) |
|