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

Username:   Password: 
 RegisterRegister   
 Help in count!!!
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DBZ




PostPosted: Thu Nov 27, 2003 9:35 pm   Post subject: Help in count!!!

i need to ask the user that For how long do they want to run the program and then after the period of time entered by the user, is over, i need to stop and exit the program. how do i do it? i am including the code that i have here so far!
Code:


%Declaring variables
var colback, ballcol:int
var x := maxx div 2
var y := maxy div 2

%Procedure
proc circle
randint(ballcol,5,225)
drawfilloval (x, y, 20, 20, ballcol)
end circle

%Setting screen
setscreen ("nocursor")

%loop statement
loop

loop
delay(10)
randint(colback,5,50)
colorback(colback)
%Exiting from the program
exit when x < 0 or x > maxx or y < 0 or y > maxy
circle
delay (50)
cls
randint (x, x - 15, x + 15)
randint (y, y - 15, y + 15)
end loop
x := maxx div 2
y := maxy div 2

end loop
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Nov 27, 2003 9:42 pm   Post subject: (No subject)

code:
clock (var c : int)


Description The clock statement is used to determine the amount of time since a program (process) started running. Variable c is assigned the number of milliseconds since the program started running.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Blade




PostPosted: Fri Nov 28, 2003 1:28 pm   Post subject: (No subject)

is clock(var c:int) just a shortcut of saying var c:int:= Time.Elapsed?
DBZ




PostPosted: Fri Nov 28, 2003 8:15 pm   Post subject: (No subject)

Hey guys i don't get it. i really don't know how to use clock statement. Can you please put it in the original code and explain it to me how it works. That i way i'd be able to see how it is used in the code.

Code:

%Declaring variables
var colback, ballcol:int
var x := maxx div 2
var y := maxy div 2

%Procedure
proc circle
randint(ballcol,5,225)
drawfilloval (x, y, 20, 20, ballcol)
end circle

%Setting screen
setscreen ("nocursor")

%loop statement
loop

loop
delay(10)
randint(colback,5,50)
colorback(colback)
%Exiting from the program
exit when x < 0 or x > maxx or y < 0 or y > maxy
circle
delay (50)
cls
randint (x, x - 15, x + 15)
randint (y, y - 15, y + 15)
end loop
x := maxx div 2
y := maxy div 2

end loop
AsianSensation




PostPosted: Fri Nov 28, 2003 8:23 pm   Post subject: (No subject)

just do this

code:

put "How long do you want the program to run (in seconds)"
get num

clock (timeRunning)
if timeRunning > num * 1000 then
    exit
end if


declare timeRunning as an integer, and the clock function returns how long the program has run since it started in milliseconds.
DBZ




PostPosted: Sun Nov 30, 2003 4:32 pm   Post subject: (No subject)

It doesn't work .
can you just put it in the original code?
Tony




PostPosted: Sun Nov 30, 2003 5:01 pm   Post subject: (No subject)

come on DBZ, think for yourself... THINK - thats the key to programming.

add
code:

var timeRunning:int


to AsianSensation's code and it would magically begin working!
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
santabruzer




PostPosted: Sun Nov 30, 2003 5:25 pm   Post subject: (No subject)

DBZ.. just use a 'for' statement..... for example.. you can do the following, and it will basically repeat itself 16 times....

code:

    var answer : int
    put "How long do you want to run the program for? (times)"
    get answer
    for i : 1 .. answer
        % put some action here
    end for

you could probably convert that into seconds..........
Andy




PostPosted: Sun Nov 30, 2003 8:21 pm   Post subject: (No subject)

when in doubt, press F10
AsianSensation




PostPosted: Sun Nov 30, 2003 9:24 pm   Post subject: (No subject)

dodge_tomahawk wrote:
when in doubt, press F10


haha, that's so true. My code is just a modified version of Turing's help file code. I'm very surprised that people don't use the help files.
DBZ




PostPosted: Mon Dec 01, 2003 2:54 pm   Post subject: (No subject)

guys i've tried everything but it just doesn't work. can you please please put your suggested codes in the original one and then try to run it. If it works please send it to me and i'll figure out what i did wrong. Thanx
Andy




PostPosted: Mon Dec 01, 2003 4:22 pm   Post subject: (No subject)

why dont u post what u have rite now and we'll help u fix it. instead of getting us to do the program for u
McKenzie




PostPosted: Mon Dec 01, 2003 5:01 pm   Post subject: (No subject)

DBZ,

Read the posts and take their advice (except the part about using whatdotcolour to cure world hunger.) When they say they won't put the answer in the original code for you don't ask them again. Ask yourself why they won't. It would be easier for everyone if we just gave you the answer in your original code. The problem with that is we would have robbed you of the joy of actually finding the answer yourself. By giving you parts they are forcing you to think (as Tony told you). If you are stuck do as dodge suggests (I think he prefers tommy these days) post your revised code. Everyone here will see the problem.

P.S. Don't comment your setscreen by saying you are setting the screen, or your loop by saying it's a loop. If the comment is obvious leave it off.
bugzpodder




PostPosted: Mon Dec 01, 2003 5:07 pm   Post subject: (No subject)

This reminds me of when somebody asked for some code in the middle of an in-class test and we gave him the code which got him 100% Laughing
bugzpodder




PostPosted: Mon Dec 01, 2003 5:08 pm   Post subject: (No subject)

dammit, the white font only works if the background is white, such as right now THIS IS GAY!!
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 2  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: