
-----------------------------------
shoobyman
Sat Feb 11, 2006 7:33 pm

really simple array problem
-----------------------------------
i am teh noob of teh forums, so can u guys help me?
i am trying to learn arrays, but no matter how much i try to call up the variable, it will not display it.
i can make it appear, but only if i use the "init" command.
this is my code, and each time i run it, it says that variable has no value.

var number: array 1..10 of int
put number (2)

-----------------------------------
Cervantes
Sat Feb 11, 2006 7:47 pm


-----------------------------------
If it says the variable has no value, it probably has a pretty good reason for saying so.

number (2) does not mean the integer, 2.  It refers to the second element of an array of variables.  

In this case, you have not assigned the second element (or any elements, for that matter) a value.  To do so, you'd do this:

number (2) := 10473

Or perhaps we could do this:

for i : 1 .. 10
    number (i) := i ** 2
end for


-----------------------------------
shoobyman
Sat Feb 11, 2006 7:53 pm


-----------------------------------
oooooooooooo, it doesn't mean integer 2, that makes more sense i just gotta declare what number (2) is, thanx!  lol me is noob :lol:

-----------------------------------
MysticVegeta
Sat Feb 11, 2006 11:38 pm


-----------------------------------
or..
var nums : array 1..5 of int := init (1, 2, 3, 4, 5)
put nums(2)

Now, you wont get an error because the corresponding element at the index of 2 is 2.

-----------------------------------
Martin
Sun Feb 12, 2006 12:04 pm

Re: really simple array problem
-----------------------------------
i am teh noob of teh forums, so can u guys help me?
i am trying to learn arrays, but no matter how much i try to call up the variable, it will not display it.
i can make it appear, but only if i use the "init" command.
this is my code, and each time i run it, it says that variable has no value.

var number: array 1..10 of int
put number (2)

What your code does is creates a set of 10 integer variables.

Your code is the equivalent of:
var number1: int
var number2: int
var number3: int
...
var number10: int
put number2

-----------------------------------
shoobyman
Sun Feb 12, 2006 6:01 pm


-----------------------------------
thank you all, very helpful, i now completely understand arrays, (it wasn't nearly as hard as i thought)  :D  :lol: .
