Write a Visual Basic program that accepts percentage score in an examination through the use of an input box function. The program then displays a remark based on the following criteria. Use case statement. (5 marks)
Score remarks
0-40 Failed
41-50 Pass
51-70 Credit
Above 70 Distinction
Answer:
Sub Main()
' Declare variables
Dim score As Integer
Dim remark As String
Dim input As String
' Get the percentage score from the user
input = InputBox("Enter the percentage score in the examination:", "Score Input")
' Validate the input and convert to integer
If IsNumeric(input) Then
score = CInt(input)
' Use Select Case to determine the remark based on the score
Select Case score
Case 0 To 40
remark = "Failed"
Case 41 To 50
remark = "Pass"
Case 51 To 70
remark = "Credit"
Case Is > 70
remark = "Distinction"
Case Else
remark = "Invalid score"
End Select
' Display the remark
MsgBox "Score: " & score & vbCrLf & "Remark: " & remark, vbInformation, "Examination Result"
Else
MsgBox "Invalid input. Please enter a numeric value.", vbExclamation, "Error"
End If
End Sub