How to code procedures in a form to : i. A function that calculates average score. ii. Another function that determines the minimum score. iii. And another to determine the maximum score.
Imports System.IO
Module Module1
Sub Main()
Dim score() As Integer = {85, 80, 88, 55, 25}
Console.WriteLine("The average score is: " & determineAverageScore(score).ToString())
Console.WriteLine("The minimum score is: " & determineMinimumScore(score).ToString())
Console.WriteLine("The maximum score is: " & determineMaximumScore(score).ToString())
Console.ReadLine()
End Sub
Function determineAverageScore(ByVal score() As Integer)
Dim sum As Double = 0
For i As Integer = 0 To score.Length - 1
sum += score(i)
Next
Return sum / score.Length
End Function
Function determineMinimumScore(ByVal score() As Integer)
Dim min As Integer = score(0)
For i As Integer = 1 To score.Length - 1
If (score(i) < min) Then
min = score(i)
End If
Next
Return min
End Function
Function determineMaximumScore(ByVal score() As Integer)
Dim max As Integer = score(0)
For i As Integer = 1 To score.Length - 1
If (score(i) > max) Then
max = score(i)
End If
Next
Return max
End Function
End Module
Comments
Leave a comment