Computer Science Canada

Timer

Author:  [Flame][Boy] [ Thu Dec 15, 2005 6:46 pm ]
Post subject:  Timer

Hey ive come up with this simple timer code but the only thing i cant figure out is why it isnt exiting at 0. Anyone know whats going on?

code:

var counter : int := 5
loop
    locate (1, 1)
    put counter - round (Time.Elapsed / 1000)
    exit when Time.Elapsed = 0
end loop

Author:  Mr. T [ Thu Dec 15, 2005 6:57 pm ]
Post subject:  Alex's Opinion

You have to understand that Time.Elapsed is a predefined Turing command. Thus, you cannot edit by performing an operation on it. Rather, you must declare a variable and store all the operations you do to Time.Elapsed in it.
code:
var counter : int := 5
var endStatement : int
loop
    locate (1, 1)
    endStatement := counter - round (Time.Elapsed / 1000)
    put counter - round (Time.Elapsed / 1000)
    exit when endStatement = 0
end loop
ode:

Author:  Mr. T [ Thu Dec 15, 2005 6:57 pm ]
Post subject:  Re: Alex's Opinion

Pwned wrote:
You have to understand that Time.Elapsed is a predefined Turing command. Thus, you cannot edit it by performing an operation on it. Rather, you must declare a variable and store all the operations you do to Time.Elapsed.
code:
var counter : int := 5
var endStatement : int
loop
    locate (1, 1)
    endStatement := counter - round (Time.Elapsed / 1000)
    put counter - round (Time.Elapsed / 1000)
    exit when endStatement = 0
end loop
ode:

Author:  McKenzie [ Thu Dec 15, 2005 6:57 pm ]
Post subject: 

Time.Elapsed will never be 0 but counter - round (Time.Elapsed / 1000) will be at some point

Author:  Mr. T [ Thu Dec 15, 2005 7:00 pm ]
Post subject:  Alex's Opinion

Sorry about the double post. Gah can someone delete the second one. Embarassed


: