To calculate the grade from the midterm and final exams we must divide (midterm+final) by 2. If we use midterm+final/2, it will find the midterm plus half of the final.
Build the form as shown below:
Horizonal Scroll Bars
Name: HsbMidterm
LargeChange = 1
Name: HsbFinal
LargeChange = 1
Labels
Name: LblInstructions
Text = "Select the number of eggs:"
Name: LblMidterm
Text = "Midterm: 0"
Name: LblFinal
Text = "Final: 0"
Name: LblAverage
Text = "Average: 0"
Write the code as shown below:
'Programmer: Janet Joy
'Select midterm and final grades to see average
Public Class Form1
Private Sub HsbMidterm_Scroll(sender As Object, e As ScrollEventArgs) Handles HsbMidterm.Scroll
'Display midterm grade and calculate average
Me.LblMidterm.Text = "Midterm: " & Me.HsbMidterm.Value
Dim average As Double = (Me.HsbMidterm.Value + Me.HsbFinal.Value) / 2
Me.LblAverage.Text = "Average: " & average
End Sub
Private Sub HsbFinal_Scroll(sender As Object, e As ScrollEventArgs) Handles HsbFinal.Scroll
'Display final grade and calculate average
Me.LblFinal.Text = "Final: " & Me.HsbFinal.Value
Dim average As Double = (Me.HsbMidterm.Value + Me.HsbFinal.Value) / 2
Me.LblAverage.Text = "Average: " & average
End Sub
End Class
Remember, you should try doing each of these programs on your own. Get it to work, break it, modify it, and then try to write it on your own!