Computer Science Canada Using arrays in a procedure |
Author: | amy616 [ Fri Nov 12, 2010 9:30 am ] | ||
Post subject: | Using arrays in a procedure | ||
What is it you are trying to achieve? I'm trying to use array variables in a procedure. The game I'm trying to make is a SUDOKU game, so I want to have about 1~81 variables for each square. What is the problem you are having? (procedure sudoku (x, y, locatex, locatey : int, num : array 1 .. 81 of int)) is my first code, and the num:array 1..81 of int does work, but when ever I wish to give the num(x) variable a value like 2 or 5 (num := value) it says that the left side is not a variable and it cannot work. Also, my line that makes the procedure work, ( sudoku (xcounter, ycounter, 35, 25, num (73))) will say that the num(73) is "Argument is the wrong type". Describe what you have tried to solve this problem I tried the game without the num(x) array variables and it works fine. When I don't have the num:=value line, it worked as well. I tried saying (var num : array 1 .. 81 of int) instead, but it didn't work. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using It says 411... so I think it is 4.1.1 version. |
Author: | DemonWasp [ Fri Nov 12, 2010 12:05 pm ] | ||||
Post subject: | RE:Using arrays in a procedure | ||||
You cannot assign a value to the whole array. You mean to say:
which will set the second element of the array to 5. Similarly, if your method expects you to pass it an array, you cannot very well pass it an integer and expect it to be happy about it. Pass it the whole num array, as follows:
Granted, none of this says anything about the wisdom of your approach. You may want to think for a good long while about exactly how your approach is going to work before programming it. It sucks to get halfway through and realize you missed something big. |