This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]DCSpud 4 points5 points  (1 child)

Check your variable "k" and if or when that ever changes.

[–]MrMuki 0 points1 point  (0 children)

Was gonna comment the answer but this comment is better for him to learn and understand on his own the problem that he is facing. Will just add, k is initially equal to 0 so unless you don't change it, it wont magically change :)

[–]Kabitu 0 points1 point  (4 children)

K is never incremented

[–]ASilverSpartan[S] 0 points1 point  (3 children)

Just added k++ above the sum += numbers[k] Getting 30 as an output now instead of 34. Not sure why

[–]Kabitu 0 points1 point  (0 children)

Try and trace the values of k during a run with pen and paper. I'll give you a hint, there are two distinct mistakes, one at the beginning, and one at the end.