Repairing an averaging routine

A Visual Basic .NET program is intended to calculate the arithmetic mean of all four force readings in newtons. Its calculation currently contains two logic errors:


Visual Basic
Dim forcesN() As Double = {6.0, 8.0, 10.0, 12.0}
Dim totalN As Double

For i As Integer = 0 To forcesN.Length - 1
    totalN = 0.0
    totalN += forcesN(i)
Next

Dim meanN As Double = totalN / (forcesN.Length - 1)


Which change fixes both errors while retaining the existing loop bounds?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Visual Basic Questions: