sum is the name of your function. You can't use that for a local variable as well.
In addition, you didn't initialise it (to zero) before you started adding to it - but that's a different sort of error.
And your loop won't run very much if you return from the function within the first pass through it.
Last edited on