Lesson goal: Using arrays to average numbers

Previous: Loops and arrays | Home | Next: Arrays and recurrence relations

In a past lesson, you learned how to use a while-loop to read in numbers and compute their average. The issue with that lesson is that the original numbers (i.e. the data) was lost! You have the average, but not the numbers that gave the average!

Since arrays can store multiple values, let's revisit taking the average of some numbers, while retaining the original numbers. Note the new construct here is the nums={} line, which tells the comptuer that variable nums is to be an array, but is empty as the program starts, hence the ={}, or "let nums be equal to an empty array right now."

Now you try. See the pink box for 3 fixes this code needs. Can you get it running?

Type your code here:

See your results here: