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

Please help, below I have pasted my code VB code. Public Class frmCIS115 Private

ID: 3875758 • Letter: P

Question

Please help, below I have pasted my code VB code.

Public Class frmCIS115
    Private Sub btnClick_Click(sender As Object, e As EventArgs) Handles btnClick.Click
        Dim number, value, counter, avg As Integer
        Dim total As Double

        DataOk()
        GetInput(value)
        ProcessNumber(value, total, counter)
        Average(total, counter, avg)
        DisplayAverage(avg)
    End Sub
    'Function to make sure the data is numeric and not less than 3 and not greater than 10
    Function DataOk() As Boolean
        If IsNumeric(txtNum.Text) = False Then
            MessageBox.Show("You must enter a number")
            txtNum.Text = ""
            txtNum.Focus()
            Return False
        ElseIf CInt(txtNum.Text) < 3 Or CInt(txtNum.Text) > 10 Then
            MessageBox.Show("Number cannot be greater 10 or less than 3!")
            txtNum.Text = ""
            txtNum.Focus()
            Return False
        Else
            Return True
        End If
    End Function
    'Subprocedure to get input
    Sub GetInput(ByRef value As Integer)
        value = CInt(txtNum.Text)
    End Sub
    'Subprocedure to display what goes in the listbox
    Sub ProcessNumber(ByVal value As Integer, ByRef total As Integer, ByRef counter As Integer)
        lstOutput.Items.Add("")
        lstOutput.Items.Add("The numbers you entered were: ")
        For i As Integer = 1 To value
            Dim number As Integer = InputBox("Please enter numbers")
            lstOutput.Items.Add(number)
            If number Mod 2 = 0 Then
                number += total
                counter += 1
            End If
        Next
    End Sub
    'Function for calculating
    Function Average(ByVal total As Integer, ByVal counter As Integer, ByRef avg As Double) As Integer
        avg = total / counter
        Return avg
    End Function
    'Function displaying average
    Function DisplayAverage(ByVal avg As Double) As String
        lstOutput.Items.Add("")
        lstOutput.Items.Add("The average of the even numbers is " & avg.ToString("n2"))
    End Function
End Class

CIS 115 - Review Enter a Number between 3 and 10: 5 Click Here The numbers you entered were 7 The average of the even numbers is 3.00

Explanation / Answer

I have seen your program and the code in the section 'Sub procedure to display what goes in the list box change the code which says,number+=total as it changes the number but doesn't change the total which you are using to find the average so this line should be changed to total+=number and you will get the correct result.