This program takes the marks of 5 students as input and finds out which one has the maximum marks. This program implements the first five topics i.e. variables(marks), output(Wscript.Echo) and input(inputBox) methods, decision making statements(if-else), loop structures(for), and procedures and functions (findmax).
The program first defines an array of size 5 named marks. Then it prompts the user to enter the marks of 5 students. These marks are stored in the marks array. After that the findmax function is called. This function receives the marks array as an argument. Inside this function, initially the first student is declared as the one having highest marks. Then its marks is compared to the marks of the other students. Whenever the marks of a student is found to be higher than the marks of students currently declared as having highest marks, its value is updated. This function returns the index of the student having highest marks. After returning, the answer is displayed.
Function findmax(marks)   ' defines a function findmax that takes an argument marks
Dim max
max = 1        ' initialize max to first student
For i=1 to 5    ' loop over the array marks
If marks(i)>marks(max) Then    ' update max if ith student is having more marks
End If
findmax=max        ' return the value of marks
End Function

Dim marks(5)           ' declare an array marks
' prompt user to enter data for 5 students and storing it in array marks
for i=1 to 5             
    marks(i) = InputBox("Enter the marks of student" & i, "Student " & i)
    If marks(i) = "" Then
            Wscript.Quit ' exit the program if user does not enter the value
End If
WScript.Echo "student having highest marks is " & findmax(marks) ' call the function findmax and print the index of student with maximum marks


The user is being prompted for entering marks 5 times, once for each student.

First time, user entered 15...

Similar Essays