display the average number of books read for all readers in a session

I am trying to display the average number of books read for all readers in a session
*The average should be displayed in the summary*

This is how my code reads:

rivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub PointsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PointsToolStripMenuItem.TextChanged

        BonusPointsTextBox.Text = calcPoints(PointsToolStripMenuItem.Text)
    End Sub

    Private Function calcPoints(ByVal input As String) As Integer
        Dim points As Integer

        Try
            Dim numBooks As Integer = Integer.Parse(input)

            If numBooks <= 3 Then
                points = numBooks * 10
            Else
                points = 3 * 10
                If numBooks <= 6 Then
                    points = points + (numBooks - 3) * 15
                Else
                    points = points + (3 * 15)
                    points = points + (numBooks - 6) * 20
                End If
            End If
        Catch ex As Exception
        End Try

        Return points
    End Function
    Friend WithEvents AverageLabel As System.Windows.Forms.Label
    Friend WithEvents AverageTextBox As System.Windows.Forms.TextBox

    Private Sub SummaryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryToolStripMenuItem.Click

    End Sub
End Class
qsykesAsked:
Who is Participating?
 
JimBrandleyCommented:
I'm not a VB programmer, but this algorithm will do what you want.
1. Add two new member variable to the form, or the class that contains your event handlers. Call them mReaders and mTotalBooks, and initialize both to zero.

2. Inside calcPoints, add this just before you return points:
  mReaders = mReaders + 1
  mTotalBooks = mTotalBooks + numBooks

3. In PointsToolStripMenuItem_Click, after
BonusPointsTextBox.Text = calcPoints(PointsToolStripMenuItem.Text)

add the VB version of this:
 AverageTextBox.Text = ((double)mTotalBooks / (double)mReaders).ToString();

where (double) is the C# cast operator that converts a numeric value to a double precision floating point operator. You may need to use a format string to limit the precision of the result string.

Jim
0
 
qsykesAuthor Commented:
Please close this wuestion. This is not the right solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.