Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I cannot get the average scores for students 2 through 6. What am I doing wrong?

ID: 3856156 • Letter: I

Question

I cannot get the average scores for students 2 through 6. What am I doing wrong? The only one that works is for the first student. This is from Starting out with Visual Basic 2016, Chapther 9, Programming Challenges, #3 Student Test Scores

·         Imports System.IO

·        

·        

·         Public Class Form1

·             Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click

·                 ' Close(program)

·                 Me.Close()

·             End Sub

·        

·        

·             Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click

·                 StudentScoreDataInput()

·             End Sub

·        

·         End Class

·        

·         Module StudentTestScoresModule

·        

·             Const intMAX_SUBSCRIPT_STUDENT As Integer = 6

·             Const intMAX_SUBSCRIPT_STUDENT_SCORES As Integer = 5

·        

·        

·             'create structure

·        

·             Public Structure StudentData

·                 Dim strName As String

·                 Dim dblTestScoresArray() As Double

·                 Dim dblAverage As Double

·             End Structure

·        

·             Dim dblTotalStd1 As Double

·             Dim dblTotalStd2 As Double

·             Dim dblTotalStd3 As Double

·             Dim dblTotalStd4 As Double

·             Dim dblTotalStd5 As Double

·             Dim dblTotalStd6 As Double

·        

·             Dim dblScore As Double

·        

·             Dim StudentsArray(intMAX_SUBSCRIPT_STUDENT) As StudentData

·        

·             Sub StudentNameDataInput()

·                 StudentsArray(0).strName = Form1.txtName1.Text

·                 StudentsArray(1).strName = Form1.txtName2.Text

·                 StudentsArray(2).strName = Form1.txtName3.Text

·                 StudentsArray(3).strName = Form1.txtName4.Text

·                 StudentsArray(4).strName = Form1.txtName5.Text

·                 StudentsArray(5).strName = Form1.txtName6.Text

·             End Sub

·        

·             Sub StudentScoreDataInput()

·                 Dim dblAverage As Double

·                 For intIndex = 0 To intMAX_SUBSCRIPT_STUDENT

·                     ReDim StudentsArray(intIndex).dblTestScoresArray(4)

·                 Next

·        

·                 'initialize test scores for first student in the array

·                 StudentsArray(0).dblTestScoresArray(0) = CDbl(Form1.txtS11.Text)

·                 StudentsArray(1).dblTestScoresArray(1) = CDbl(Form1.txtS12.Text)

·                 StudentsArray(2).dblTestScoresArray(2) = CDbl(Form1.txtS13.Text)

·                 StudentsArray(3).dblTestScoresArray(3) = CDbl(Form1.txtS14.Text)

·                 StudentsArray(4).dblTestScoresArray(4) = CDbl(Form1.txtS15.Text)

·        

·        

·        

·                 For Each i As StudentData In StudentsArray

·                     For Each S As Double In i.dblTestScoresArray

·                         dblTotalStd1 += S

·                     Next

·                 Next

·                 dblAverage = dblTotalStd1 / intMAX_SUBSCRIPT_STUDENT_SCORES

·                 Form1.lblAvg1.Text = (dblAverage.ToString)

·             End Sub

·        

·             Sub CalculateAverage()

·             End Sub

·        

·         End Module

Explanation / Answer

Imports System.IO

·        

·        

·         Public Class Form1

·             Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click

·                 ' Close(program)

·                 Me.Close()

·             End Sub

·        

·        

·             Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click

·                 StudentScoreDataInput()

·             End Sub

·        

·         End Class

·        

·         Module StudentTestScoresModule

·        

·             Const intMAX_SUBSCRIPT_STUDENT As Integer = 6

·             Const intMAX_SUBSCRIPT_STUDENT_SCORES As Integer = 5

·        

·        

·             'create structure

·        

·             Public Structure StudentData

·                 Dim strName As String

·                 Dim dblTestScoresArray() As Double

·                 Dim dblAverage As Double

·             End Structure

·        

·             Dim dblTotalStd1 As Double

·             Dim dblTotalStd2 As Double

·             Dim dblTotalStd3 As Double

·             Dim dblTotalStd4 As Double

·             Dim dblTotalStd5 As Double

·             Dim dblTotalStd6 As Double

·        

·             Dim dblScore As Double

·        

·             Dim StudentsArray(intMAX_SUBSCRIPT_STUDENT) As StudentData

·        

·             Sub StudentNameDataInput()

·                 StudentsArray(0).strName = Form1.txtName1.Text

·                 StudentsArray(1).strName = Form1.txtName2.Text

·                 StudentsArray(2).strName = Form1.txtName3.Text

·                 StudentsArray(3).strName = Form1.txtName4.Text

·                 StudentsArray(4).strName = Form1.txtName5.Text

·                 StudentsArray(5).strName = Form1.txtName6.Text

·             End Sub

·        

·             Sub StudentScoreDataInput()

·                 Dim dblAverage As Double

·                 For intIndex = 0 To intMAX_SUBSCRIPT_STUDENT

·                     ReDim StudentsArray(intIndex).dblTestScoresArray(4)

·                 Next

·        

·                 'initialize test scores for first student in the array

·                 StudentsArray(0).dblTestScoresArray(0) = CDbl(Form1.txtS11.Text)

·                 StudentsArray(1).dblTestScoresArray(1) = CDbl(Form1.txtS12.Text)

·                 StudentsArray(2).dblTestScoresArray(2) = CDbl(Form1.txtS13.Text)

·                 StudentsArray(3).dblTestScoresArray(3) = CDbl(Form1.txtS14.Text)

·                 StudentsArray(4).dblTestScoresArray(4) = CDbl(Form1.txtS15.Text)

·        

·        

·        

·                 For Each i As StudentData In StudentsArray

·                     For Each S As Double In i.dblTestScoresArray

·                         dblTotalStd1 += S

·                     Next

·                 Next

·                 dblAverage = dblTotalStd1 / intMAX_SUBSCRIPT_STUDENT_SCORES

·                 Form1.lblAvg1.Text = (dblAverage.ToString)

·             End Sub

·        

·             Sub CalculateAverage()

·             End Sub

·        

·         End Module

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote