Computer Science Canada variables defined by changing variables |
| Author: | chipanpriest [ Thu Oct 25, 2012 6:39 pm ] | ||||
| Post subject: | variables defined by changing variables | ||||
Hi, I've ran into a problem with my program. I'm not sure if it's even solvable. I am working on remaking hangman. My program chooses a random word from a list of 20 words and has the user guess what it is. Everything works fine, the first time. I want to put my program in a loop so that the user can play multiple games of hangman without having to exit and restart the program. The problem is, I have procedures that require a variable that has a value. I'll show you some of my code:
As you can see, variable l is defined by the length of the word. This is used later in the program to center the word. If I want the user to play multiple times, e would have to randomize in a loop. However, letter has an upper set to the length of the word. Is there a way I can reset the perimeters of that variable every time my program goes through the loop? That isn't my only problem <insert sarcastic comment about me having problems here>. My program also contains many procedures, and some of these procedure depend on l. For example:
If I try to put a procedure in a loop, turing yells at me. If I try to randomize e in a loop and set l as the length of word(e), my procedures yell at me about not having a value for the variables inside them. Like I said, I'm not sure if my problems can be solved, but any help would be greatly appreciated. I added my file, but it may not be much help because the pictures and text file do not come with it, so basically you can read my code but not run it. I know I could have compressed the folder, but I'm feeling a little lazy right now, so tough luck, Chuck. |
|||||
| Author: | Aange10 [ Thu Oct 25, 2012 6:44 pm ] | ||
| Post subject: | RE:variables defined by changing variables | ||
Quote: Is there a way I can reset the perimeters of that variable every time my program goes through the loop?
Do you know of flexible arrays? Other than that, redefining the variable each time should solve the problem. Try having a procedure to do it. For example:
|
|||
| Author: | chipanpriest [ Thu Oct 25, 2012 7:03 pm ] |
| Post subject: | Re: RE:variables defined by changing variables |
Aange10 @ Thu Oct 25, 2012 6:44 pm wrote: Do you know of flexible arrays? Awesome! Thanks, it works now! I'll be looking forward to sharing this on the site! |
|
| Author: | Raknarg [ Fri Oct 26, 2012 8:29 am ] |
| Post subject: | RE:variables defined by changing variables |
Or lists. But that's totally unecessary atm. |
|
| Author: | Aange10 [ Fri Oct 26, 2012 11:08 am ] |
| Post subject: | Re: RE:variables defined by changing variables |
Raknarg @ 26/10/2012, 7:29 am wrote: Or lists. But that's totally unecessary atm.
There are lists in Turing? |
|
| Author: | TerranceN [ Fri Oct 26, 2012 8:16 pm ] | ||
| Post subject: | Re: variables defined by changing variables | ||
Yep, but you have to make them yourself using pointers. Here's a really basic implementation using cons cells.
|
|||
| Author: | Aange10 [ Sat Oct 27, 2012 12:18 pm ] |
| Post subject: | RE:variables defined by changing variables |
Oh a linked list. I was thinking more along the lines of like Python's lists. |
|