Computer Science Canada

Why does this not work

Author:  Luffy123 [ Wed Jun 06, 2012 8:06 am ]
Post subject:  Why does this not work

I got this from the turing documentation.

code:

var howMany : int
get howMany
var height : array 1 .. howMany of real

function total (a : array 1 .. * of real) : real
    var sum : real := 0
    for i : 1 .. upper (a)
        sum := sum + a (i)
    end for
    result sum
end total

put "Sum of the heights is ", total (height)



I dont' understand why it doesn't work. The error I get is

sum := sum + a (i)

Variable has no value in this line

Author:  Amarylis [ Wed Jun 06, 2012 8:21 am ]
Post subject:  RE:Why does this not work

Look carefully at the code: Which one of the two in that line do you know already has a value, sum, or a (i)?


: