Yea, you need to use your index, which in your case is counter.

sum += a[counter];


Dejan