I'm trying to write a simple program that computes the sum of the series 1^2 + 2^2 + 3^2... such that the sum is as large as possible without exceeding 1000. I need to use a while loop in this program. Here's my code so far:
So my basic idea here was to place each number squared into an array, then sum the array and check to see if it makes the sum condition (<= 1000) and if not go up and plug the next number into the array etc. But this doesn't work and I'm not sure why. Any pointers?