0

sorry if this is really nooby but i cant seem to get pass the basics.
i need to write a program that accepts a series of exam marks, ended by -1. When the -1 is entered, it should display the following results in a text box,:
The average (mean) mark
The smallest and largest mark.
"Great work" if at least 30% of the students passed (got 40% or above). If not, it should display "High failure rate
Thank you for any help you cant offer

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by choudhuryshouvi
0

use the following code. before use it take three textboxes(text1,trxt2,text3); one listbox(list1) ; one label(label1); and a commandbutton(command1)

Option Explicit

Private Sub Command1_Click()
Dim num As Integer

num = 0
begin:
num = InputBox("Enter exam marks. -1 to end", "Marks")
If num > -1 Then
    List1.AddItem num
    GoTo begin
End If

Text1.Text = "Max :" & GetMaxMark
Text2.Text = "Min :" & GetMinMark
Text3.Text = "Avg :" & GetAvg
Call Result
End Sub

Public Function GetMaxMark() As Integer        'to find out the maximum mark
Dim i As Integer, max As Integer

max = 0
For i = 0 To List1.ListCount - 1 Step 1
    If Val(List1.List(i)) > max Then
        max = Val(List1.List(i))
    End If
Next i

GetMaxMark = max
End Function

Public Function GetMinMark() As Integer               'to find out the minimum mark
Dim i As Integer, min As Integer

min = List1.List(0)
For i = 0 To List1.ListCount - 1 Step 1
    If Val(List1.List(i)) < min Then
        min = Val(List1.List(i))
    End If
Next i

GetMinMark = min
End Function

Public Function GetAvg() As Double            'to find out the average
Dim i As Integer, sum As Integer

sum = 0
For i = 0 To List1.ListCount - 1 Step 1
    sum = sum + Val(List1.List(i))
Next i

GetAvg = sum / List1.ListCount
GetAvg = Format(GetAvg, "0.00")
End Function

Public Sub Result()            'to print the overall result status
Dim i As Integer, above40 As Integer, per As Double

above40 = 0
For i = 0 To List1.ListCount - 1 Step 1
    If Val(List1.List(i)) >= 40 Then
        above40 = above40 + 1
    End If
Next i

per = (above40 * 100) / List1.ListCount
If per >= 30 Then
    Label1.Caption = "GREAT WORK" & vbCrLf & "Passing Rate :" & per & "%"
Else
    Label1.Caption = "HIGH FAILURE RATE" & vbCrLf & "Passing Rate :" & per & "%"
End If
End Sub

see the screenshot also

hope this will help you
regards
Shouvik

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.