Computer Science Canada Help with clock |
Author: | canada123 [ Tue May 16, 2006 8:15 pm ] |
Post subject: | Help with clock |
Hey, i just started turing and i would like to know how make a clock that increases in minutes and seconds. I have attempted to make one but it is very poor and only counts in seconds. Thnxs |
Author: | Delos [ Tue May 16, 2006 8:28 pm ] |
Post subject: | |
Good to know you've got the seconds going. That's the easy part. Next step will be to parse those seconds into minutes and hours. How many seconds in a minute? How many minutes in an hour? Now, stick in a couple of 'div's here and there, and you're good to go. That being said, in future please include your code when you post a question, it will help us understand you a little better and help a lot more. For instance, I'm not even certain if I answered your question. I will point you to the Turing Help file, under the heading of Time.Date(). This is an easy way out, and I'm sure you'd rather create something yourself, so keep us up-to-date on how your progress. |
Author: | canada123 [ Tue May 16, 2006 8:55 pm ] |
Post subject: | |
[b][b]var minutes : int var seconds : int seconds := 0 minutes := 0 for i : 1 .. 60 put minutes, ":", seconds seconds := seconds + 1 delay (1000) cls end for[/b][/b] When the seconds get to 60 the program finishes, as expected. I want to know how to make minutes = 1 when seconds = 60...maybe the "when" command would be of use? |
Author: | canada123 [ Tue May 16, 2006 9:08 pm ] |
Post subject: | |
Hey thnxs delos for the help, but i figured it out. I might be back later. Cya |
Author: | Clayton [ Tue May 16, 2006 11:09 pm ] | ||||
Post subject: | |||||
hello, plz use
|
Author: | TheOneTrueGod [ Wed May 17, 2006 1:58 pm ] |
Post subject: | |
You don't even need a bunch of variables to keep track of that. You can just parse the Time.Elapsed value to come up with that. For example, Time.Elapsed div 1000 will give you the seconds, right? Well, if that value is greater than 60, then obviously a minute has passed. Can you think of a way to use basic math (div and mod) to calculate the minutes? |
Author: | MysticVegeta [ Wed May 17, 2006 6:14 pm ] | ||
Post subject: | |||
simple mod functions would do this...
|
Author: | TheOneTrueGod [ Wed May 17, 2006 6:38 pm ] |
Post subject: | |
ugh, allright, fine, I'll just give the solution then. put "Hours: ", ( (Time.Elapsed div 1000) div 60) div 60) %Note: this line can be reduced to Time.Elapsed div 3600000 if you really feel like it. put "Minutes: ", ((Time.Elapsed div 1000) div 60) mod 60 %Note: this line can be reduced to Time.Elapsed div 60000 if you really feel like it. put "Seconds: ",(Time.Elapsed div 1000) mod 60 put "Milliseconds: ", Time.Elapsed mod 1000 The less variables your program has, the less memory its going to waste, and the more you can manage with one variable (function in this case), the better your math "skillz to pay da billz" will get. |
Author: | canada123 [ Wed May 17, 2006 6:51 pm ] | ||
Post subject: | |||
Although there maybe to many variables. . . this is what I came up with and works pretty well with my program. ps: I may need some help with forks
|
Author: | canada123 [ Wed May 17, 2006 6:53 pm ] |
Post subject: | |
How do I make two things run in a loop at once? Do I need to use forks? and if so, how? |
Author: | [Gandalf] [ Wed May 17, 2006 7:05 pm ] | ||||
Post subject: | |||||
Nein! It'll help to know exactly what you are trying to do, but why not just do it sequentially? Just put the two things you are trying to do right after one another. For example:
Will result in doFoo() and doBar() running, at least to the user, "at once". It executes exactly the same as:
|
Author: | canada123 [ Wed May 17, 2006 7:51 pm ] | ||
Post subject: | |||
I would like to know (if possible) how to be able to change the score while the time continues to run
|
Author: | TheOneTrueGod [ Wed May 17, 2006 7:55 pm ] | ||
Post subject: | |||
you could do a:
|