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

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




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




PostPosted: Tue May 16, 2006 8:28 pm   Post subject: (No 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.
canada123




PostPosted: Tue May 16, 2006 8:55 pm   Post subject: (No 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?
canada123




PostPosted: Tue May 16, 2006 9:08 pm   Post subject: (No subject)

Hey thnxs delos for the help, but i figured it out. I might be back later. Cya
Clayton




PostPosted: Tue May 16, 2006 11:09 pm   Post subject: (No subject)

hello, plz use
code:
tags when posting, now on to your question, if you want to check if 60 seconds has passed, just have a simple if statement
code:

if seconds=60 then
    minutes+=1%same as minutes:=minutes+1
    seconds:=0%so we have 1:00 instead of 1:60
end if
TheOneTrueGod




PostPosted: Wed May 17, 2006 1:58 pm   Post subject: (No 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?
MysticVegeta




PostPosted: Wed May 17, 2006 6:14 pm   Post subject: (No subject)

simple mod functions would do this...
code:
var minutes := 0
var second := 0
loop
    second := (second + 1) mod 60
    if second = 0 then
        minutes += 1
    end if
    put minutes, " ", second
    Input.Pause
end loop
TheOneTrueGod




PostPosted: Wed May 17, 2006 6:38 pm   Post subject: (No 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.
Sponsor
Sponsor
Sponsor
sponsor
canada123




PostPosted: Wed May 17, 2006 6:51 pm   Post subject: (No 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

code:

var team1, team2 : string
var seconds, minutes : int

minutes := 0
seconds := 0

loop
    put "Time:", minutes, ":", seconds
    seconds := seconds + 1
    delay (1000)
    cls
    if seconds = 60 then
    minutes := minutes + 1
    seconds := 0
    end if
    exit when minutes = 60
end loop

a
canada123




PostPosted: Wed May 17, 2006 6:53 pm   Post subject: (No subject)

How do I make two things run in a loop at once? Do I need to use forks? and if so, how?
[Gandalf]




PostPosted: Wed May 17, 2006 7:05 pm   Post subject: (No 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:
code:
var someNumber : int := 45
proc doFoo
    someNumber += 1   
end doFoo
proc doBar
    someNumber *= 2
end doBar
for i : 1 .. 5
    doFoo
    doBar
    put i, ": ", someNumber
end for

Will result in doFoo() and doBar() running, at least to the user, "at once". It executes exactly the same as:
code:
var someNumber : int := 45
for i : 1 .. 5
    someNumber := (someNumber + 1) * 2
    put i, ": ", someNumber
end for
canada123




PostPosted: Wed May 17, 2006 7:51 pm   Post subject: (No subject)

I would like to know (if possible) how to be able to change the score while the time continues to run

code:

setscreen ("graphics:max;max")
var team1, team2, winner, name, goal, enter : string
var row, column, x, y, score, font, seconds, minutes, score1, score2, digit1 : int

put "Enter the name of the first team that is playing:" ..
get team1
put "Enter the name of the second team that is playing:" ..
get team2
cls

%----------------------------------------------

row := 9
column := 22
x := 50
y := -100

%----------------------------------------------

seconds := 0
minutes := 0
row := 16
column := 48
digit1 := 0
score1 := 0
score2 := 0

%----------------------------------------------

loop
    locate (1, 1)
    put "Enter the team name that scored and press enter:"..
    get goal
    cls
    if goal = team1 then
    score1 := score1 + 1
    elsif goal = team2 then
    score2 := score2 + 1
    end if   
    locate (row, column)
    put "Time:", minutes, ":", seconds, "  ", team1, ":", score1, " ", team2, ":", score2
   
    seconds := seconds + 1
    delay (1000)
    if seconds = 60 then
        minutes := minutes + 1
    seconds := 0
    end if
    exit when minutes = 45
end loop
TheOneTrueGod




PostPosted: Wed May 17, 2006 7:55 pm   Post subject: (No subject)

you could do a:

code:

loop
  %pseudocode + a bit of turing code
  if hasch then
     ch := getchar
  end if
  if ch = '1' then
     calculate score and stuff
  elsif ch = '2' then
     calculate score and stuff
  end if
  output time stuff
end loop
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  [ 13 Posts ]
Jump to:   


Style:  
Search: