Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Rounding minutes
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
BiggZigg9




PostPosted: 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
Sponsor
sponsor
2goto1




PostPosted: Thu Jan 20, 2011 9:55 am   Post subject: RE:Rounding minutes

The modulus operator might be your friend here
Zren




PostPosted: 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




PostPosted: 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




PostPosted: Thu Jan 20, 2011 12:52 pm   Post subject: RE:Rounding minutes

Yes, you are looking for ceil type rounding.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
BiggZigg9




PostPosted: Thu Jan 20, 2011 12:54 pm   Post subject: RE:Rounding minutes

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




PostPosted: Thu Jan 20, 2011 12:58 pm   Post subject: RE:Rounding minutes

yah ceiling better than modulus in this case
Insectoid




PostPosted: 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
Sponsor
sponsor
Tony




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: