Computer Science Canada program won't restart |
Author: | blankout [ Sat Apr 04, 2009 7:36 pm ] | ||
Post subject: | program won't restart | ||
even with the procedure, i can't seem to get the program to restart after one cycle, please help the program works fine, it's just that it doesn't repeat
|
Author: | Dusk Eagle [ Sat Apr 04, 2009 8:22 pm ] | ||
Post subject: | Re: program won't restart | ||
There's quite a few problems with your code. First of all, there is no need to be asking the user for the length of name. Instead, look up the length command. Second of all, your program is using global variables, which are a very bad thing. Read up on how to use parameters with your procedures/functions here. (Hint - name should be passed as a parameter, whereas counter and (if used) letters should be declared inside the procedure.) Now take a look at the structure of your code. Does it ask for the user's name again? No, so you wouldn't expect it to repeat. But maybe you simply want the same name to "fade out" over and over again. Either way, look at your "exit when counter = -1" line. If we comment out the current put statement and add
we see that counter is continually increasing, not decreasing. So instead of exiting when the counter = -1, when would it make more sense to exit? I'll let you figure that part out yourself. Now, once you have done all the above, to make the effect occur over and over again, simply add a loop around your "restart" line, and you'll witness the effect over and over again. |
Author: | blankout [ Sat Apr 04, 2009 8:49 pm ] | ||
Post subject: | Re: program won't restart | ||
ok well i tried to do what you said, and what i got is that the name still fades away, however i still can't repeat it, and i'm not entirely sure if i've gotten the exit when part correct this is what i've managed to do
|
Author: | Dusk Eagle [ Sat Apr 04, 2009 10:53 pm ] | ||||||||
Post subject: | Re: program won't restart | ||||||||
You're very close to having your program working, only two things left to do. The first is to take out the line within your restart procedure that says nothing except "restart". What you have done is known as "recursion", which although not a bad thing, it is definitely not something you wanted to do here. The second thing you need to do is declare your counter variable inside your 'restart' procedure, rather than outside, like so:
The final thing to do is to loop calling the procedure, like so:
Do these three things and you'll have your program working. However, if you want to take a bonus step, look at the following code:
Notice the "procedure restart(word:string)" and the "restart(name)"? The restart(name) line "passes" the value of name into the procedure restart, which then stores a copy of that value known as word. One of the many advantages to doing it this way is demonstrated below:
Notice how we could use more than one variable with restart()? This will prove to be immensely useful to you later on, and so is a good practice to start now. |
Author: | blankout [ Mon Apr 06, 2009 2:56 pm ] |
Post subject: | Re: program won't restart |
wow that fixed every problem i had thank you so much! |