MEX5-15 , averaging student grades.

! MExample Program 5-15

! Ask user to specify the number of a student, and

! average the grades of that student while dropping

! the lowest grade.

! only students 17 and 9 have grade files

! do trace, fast (Number$,Grade, Count)

 

PRINT "Only students 9 and 17 have grade files."

INPUT prompt "Enter student number: ": Number$

IF Val(Number$) < 10 then LET Number$ = "0" & Number$

LET FileName$ = "GRADES" & Number$ & ".DAT"

PRINT FileName$

OPEN #1: name FileName$

LET Count = 0

LET Sum = 0

LET Lowest = 100

DO until End #1

INPUT #1: Grade

IF Grade < Lowest then LET Lowest = Grade

LET Count = Count + 1

LET Sum = Sum + Grade

LOOP

LET Count = Count - 1 ! adjust for drop

LET Sum = Sum - Lowest

LET Average = Round(Sum/Count)

PRINT "Average grade is"; Average

END

The output of the program for student 9 is:

Only students 9 and 17 have grade files.

Enter student number: 9

GRADES09.DAT

Average grade is 86

The output of the program for student 17 is:

Only students 9 and 17 have grade files.

Enter student number: 17

GRADES17.DAT

Average grade is 90


The output of the program for student 3 is:

An error message "no such file".

The text file GRADES09.DAT contains:

70

63

92

100

80

92

85

91

78

88

82

90