Write a program in visual basic that accepts a name and a score of six students in a test
through the use of inputbox(). The program should then display the names, scores and the average scores on a picturebox. Attach the code to a command button
Answer:
Private Sub btnDisplay_Click()
Dim names(5) As String
Dim scores(5) As Double
Dim totalScore As Double
Dim averageScore As Double
Dim i As Integer
' Loop to accept names and scores for six students
For i = 0 To 5
names(i) = InputBox("Enter name for student " & (i + 1) & ":")
scores(i) = Val(InputBox("Enter score for " & names(i) & ":"))
Next i
' Calculate the total score
totalScore = 0
For i = 0 To 5
totalScore = totalScore + scores(i)
Next i
' Calculate the average score
averageScore = totalScore / 6
' Display names, scores, and average score on the PictureBox
picDisplay.Cls
picDisplay.Print "Name", "Score"
picDisplay.Print "-------------------"
For i = 0 To 5
picDisplay.Print names(i), scores(i)
Next i
picDisplay.Print "-------------------"
picDisplay.Print "Average Score: ", averageScore
End Sub