
-----------------------------------
DBZ
Thu Nov 27, 2003 9:35 pm

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

-----------------------------------
Tony
Thu Nov 27, 2003 9:42 pm


-----------------------------------
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.

-----------------------------------
Blade
Fri Nov 28, 2003 1:28 pm


-----------------------------------
is clock(var c:int) just a shortcut of saying var c:int:= Time.Elapsed?

-----------------------------------
DBZ
Fri Nov 28, 2003 8:15 pm


-----------------------------------
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
Fri Nov 28, 2003 8:23 pm


-----------------------------------
just do this


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
Sun Nov 30, 2003 4:32 pm


-----------------------------------
It doesn't work . 
can you just put it in the original code?

-----------------------------------
Tony
Sun Nov 30, 2003 5:01 pm


-----------------------------------
come on DBZ, think for yourself... THINK - thats the key to programming.

add

var timeRunning:int


to AsianSensation's code and it would magically begin working!

-----------------------------------
santabruzer
Sun Nov 30, 2003 5:25 pm


-----------------------------------
DBZ.. just use a 'for' statement..... for example.. you can do the following, and it will basically repeat itself 16 times.... 


    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
Sun Nov 30, 2003 8:21 pm


-----------------------------------
when in doubt, press F10

-----------------------------------
AsianSensation
Sun Nov 30, 2003 9:24 pm


-----------------------------------
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
Mon Dec 01, 2003 2:54 pm


-----------------------------------
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
Mon Dec 01, 2003 4:22 pm


-----------------------------------
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
Mon Dec 01, 2003 5:01 pm


-----------------------------------
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
Mon Dec 01, 2003 5:07 pm


-----------------------------------
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% :lol:

-----------------------------------
bugzpodder
Mon Dec 01, 2003 5:08 pm


-----------------------------------
dammit, the white font only works if the background is white, such as right now THIS IS GAY!!

-----------------------------------
Andy
Mon Dec 01, 2003 6:27 pm


-----------------------------------
lol... tony make mckenzie a mod... lol i'd love to see me get banned by my compsci teacher

-----------------------------------
DBZ
Mon Dec 01, 2003 8:21 pm


-----------------------------------
I am telling yo! i have tried every single thing but it just won't work i don't know why. Here i am giving u what i have so far and put your suggestions in the program please. THanx!!!!!!

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

-----------------------------------
Andy
Mon Dec 01, 2003 8:31 pm


-----------------------------------
wtf? you didnt even change anything from ur original code!!! do you not take in our comments? arg fine i'll do it for you... mckeanzie dont kill me... lol

var runtime : int
put "run for how many seconds?"
get runtime
runtime += 1
runtime *= 1000

%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
        if Time.Elapsed >= runtime then
            colorback (white)
            cls
            put "good bye"
            return
        end if
        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
Mon Dec 01, 2003 8:48 pm


-----------------------------------
jeez DBZ, why don't you show us what you tried to do? Maybe then we will show you what you did wrong. I mean, do you not understand the concept of working stuff out by yourself? This time you got lucky, you managed to annoy andy so much that he did the thing for you, tell me, if your teacher asks another question like that, are you going to be able to do it? What if he asks you this on the test? Huh? What? How are you going to survive then?

I am telling yo! i have tried every single thing but it just won't work i don't know why. Here i am giving u what i have so far and put your suggestions in the program please. THanx!!!!!!

you tried everything? Really now, if you tried everything, then you would be able to do that program. We gave you all the stuff you need to do this thing. I even gave you the code, tony even suggested defining the variable. We explained how clock works, so why don't you spend some time thinking it out? Maybe if you took two seconds out of your busy life to think then you can actually do that program? Seriously, doesn't it take longer to type out that stuff then to think about the program?

p.s. tony, make me a turing mod so I can edit these posts, jeez.

-----------------------------------
Andy
Mon Dec 01, 2003 8:51 pm


-----------------------------------
me 2  :D 
plz? lol
o and DBZ u noe... it took me less time to do the program than to post all my replies...
