I got tuday an exercise:
Write a program to calculate the average of three exam marks. The input and output should be done by subprograms GetMarks and DisplayAverage respectively. the calculation should be done by a function, CalcAverage.
This is my code:
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click Dim student As String, exam1 As Integer, exam2 As Integer, exam3 As Integer Dim average As Double lstResult.Items.Clear() GetMarks(student, exam1, exam2, exam3) average = calcAverage(exam1, exam2, exam3) DisplayAverage(student, average) End Sub Private Sub GetMarks(ByRef student As String, ByVal exam1 As Integer, ByVal exam2 As Integer, ByVal exam3 As Integer) student = txtName.Text Integer.TryParse(txtExam1.Text, exam1) Integer.TryParse(txtExam2.Text, exam2) Integer.TryParse(txtExam3.Text, exam3) End Sub Private Function CalcAverage(ByVal exam1 As Integer, ByVal exam2 As Integer, ByVal exam3 As Integer) As Double Return (exam1 + exam2 + exam3) / 3 End Function Private Sub DisplayAverage(ByVal student As String, ByVal average As Double) lstResult.Items.Add("Average for " & student & " is " & average)
I think that I messes up smthg and it's showing me average = 0.
Can any correct it for me