The biggest problem that I see is that
last
is always going to equal
in
Are you getting the right first number?
Have you made any progress? I got it to work in C# with a few modifications. They're pretty small modifications.
As you're going, if you know that you've reached the maxsum so far, you want to set that
i
value as the
last
value. so
if (sum > maxsum)
{
maxsum = sum;
last = i;
}
Then, you just need to change the last for from
i<last
to
i<=last
.
That should give you what you're expecting.