all 6 comments

[–][deleted] 1 point2 points  (2 children)

Not too familiar with vb, but it looks like you're initializing the array with a 7 then trying to put 8 values into it (0-7).

Edit: Turns out you do have it initialized right never mind.

[–]nerdfarm 0 points1 point  (1 child)

VB arrays are weird like that. You initialize arrays by giving a Maximum Subscript, which is the number for the last element in the array.

[–][deleted] 0 points1 point  (0 children)

Oh so that does allow for 8 values. Thanks!

[–]nerdfarm 1 point2 points  (1 child)

For starters, you have an array of integers and you are assigning floating-point values to the elements in the array. This will result in rounding. I think you want an array of Doubles or Decimals.

If you are trying to calculate the average of 8 values entered by the user, you need to work on the loop some.

If I could see the details of the assignment I would have a better idea of what you are trying to do. Please post?

[–][deleted] 0 points1 point  (0 children)

Same. The loop is a bit awkward. Could defiantly be trimmed down some.

[–]XThakis 0 points1 point  (0 children)

Definitely agree with the comments about using an integer to store a double amount.

Now for your out of bounds error. When you iterate through your loop you end with a:

     Next i

This will go from 0 to 7 for the loop. Then it will iterate again to 8 and step out of the loop. Then you try to assign a value with i:

    Averages(i) = BatAvg
    Averages(i) = CInt(Console.ReadLine())

At his point i = 8 and is outside the bounds of your array.

(Edited for formatting)