
-----------------------------------
Fashoomp
Tue Feb 26, 2008 6:08 pm

Array Addition
-----------------------------------
I have an array thats 1..30, and all 30 contain numbers
I want another array to store the results of addition within the array.

I want addition_array (i) := num_array (i) + num_array (i+1)
Problem is for the final value, (i+1) is out of range.

-----------------------------------
syntax_error
Tue Feb 26, 2008 6:11 pm

RE:Array Addition
-----------------------------------
trace though your program :L

you will see that the reason why you get out of range is you are looking for the 31st index; doesnt exist.

I do that that is your problem.

-----------------------------------
Tony
Tue Feb 26, 2008 6:11 pm

RE:Array Addition
-----------------------------------
well if your range is up to 30 and you want i + 1 to be the final value, what should i go up to? that is:

i + 1 = 30
i = ?

-----------------------------------
OneOffDriveByPoster
Tue Feb 26, 2008 6:12 pm

Re: Array Addition
-----------------------------------
So... your addition_array has one less entry, or you assume that the missing value is 0, or that the source array is circular, etc.

-----------------------------------
Fashoomp
Tue Feb 26, 2008 6:15 pm

Re: Array Addition
-----------------------------------
That doesn't help, since my code is (i+1) - (i)

I need to subtract value 2 from 1, then 3 from 2, then 4 from 3, etc.

The array of 30 was just an example. My array size is actually the length of a word I have entered.

-----------------------------------
Tony
Tue Feb 26, 2008 6:17 pm

RE:Array Addition
-----------------------------------
it doesn't make a difference. Just make sure that

max_i + 1 == length_of_word

-----------------------------------
Fashoomp
Tue Feb 26, 2008 6:18 pm

Re: Array Addition
-----------------------------------
Yes, the missing value in the addition array is a 0.

-----------------------------------
syntax_error
Tue Feb 26, 2008 6:19 pm

Re: Array Addition
-----------------------------------

Yes, the missing value in the addition array is a 0.


care to clarify?

-----------------------------------
Fashoomp
Tue Feb 26, 2008 6:20 pm

Re: RE:Array Addition
-----------------------------------
it doesn't make a difference. Just make sure that

max_i + 1 == length_of_word

But thats impossible. The fact that its i+1 means that it will always exceed the value of the for loop (sorry if I never mentioned thats what I'm using)

-----------------------------------
Tony
Tue Feb 26, 2008 6:23 pm

RE:Array Addition
-----------------------------------
hmm... really?

let word = "think"
then length_of_word := length(word)
length_of_word == 5

let max_i = length_of_word - 1
max_i == 4

max_i + 1 == length_of_word
4 + 1 == 5

QED

-----------------------------------
Fashoomp
Tue Feb 26, 2008 6:23 pm

Re: Array Addition
-----------------------------------
Sorry for double post

Would a conditional loop be better for adding my values to the array? Since I can just tell the loop to exit at word_length - 1, so my variable + 1 is my last array value?

That sounds right so I'm gonna go with that.

-----------------------------------
syntax_error
Tue Feb 26, 2008 6:24 pm

RE:Array Addition
-----------------------------------
glad you can think it out. Try that again next time.

-----------------------------------
Nick
Tue Feb 26, 2008 6:43 pm

RE:Array Addition
-----------------------------------

for i:2..length of word
word(i)+word(i-1)
end for
 

or


for i 1..length of word + 1
word(i) + word (i+1) %this will produce an error though
end for

