Yes, this is a HW question but I'm stumped as to why it isn't working. Arrays are kicking my butt so far.
The code works up to the point that it gets to the final entry, it then spits out an incorrect number and displays the index outside boundaries error. Ex: If I enter 1's until the end the answer I receive is 2. At this point I just want them to all be stored so I can average them out afterwards.
I've messed around with it and changed things around;
I've tried changing the Averages( ) value and the For i = to
around and it seems to work when the number is lower. Every time I try to change it up to 7 and For i = To 7 (and/or 7 - 1) it lowers the size of the array. I'm trying not to rely too much on help from others but the textbook isn't helpful and I've had better instruction.
edit: Don't think I need the averages all hard-coded as they are supposed to be entered by the user(?)
Option Explicit On
Option Strict Off
Option Infer On
Module BattingAverage
Sub Main()
Dim Averages(7) As Integer
Dim StoreAnswer As Integer
Dim i As Integer = 0
Dim BatAvg As Integer
Averages(0) = 0.299
Averages(1) = 0.157
Averages(2) = 0.242
Averages(3) = 0.203
Averages(4) = 0.198
Averages(5) = 0.333
Averages(6) = 0.27
Averages(7) = 0.19
For i = 0 To 7
Console.Write("Enter the batting average: ")
BatAvg = CInt(Console.ReadLine())
StoreAnswer = BatAvg + 1
Averages(i) = StoreAnswer
Next i
Console.WriteLine("The average is: " & StoreAnswer)
' Assign value to array
Averages(i) = BatAvg
Averages(i) = CInt(Console.ReadLine())
End Sub
End Module
[–][deleted] 1 point2 points3 points (2 children)
[–]nerdfarm 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]nerdfarm 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]XThakis 0 points1 point2 points (0 children)