At the end of a quarter, the average of three marks must be computed. Then, this average is rounded and used to determine the corresponding letter grade. The letter grades are computed as follows:
| Range | Grade |
| >= 90 | A |
| < 90 and >= 85 | AB |
| < 85 and >= 80 | B |
| < 80 and >= 75 | BC |
| < 75 and >= 70 | C |
| < 70 and >= 65 | CD |
| < 65 and >= 60 | D |
| < 60 | F |
Write a program to read three marks, compute its average, round the average
and use it to determine the corresponding letter grade.
! ----------------------------------------------------------
! This program reads three marks, computes their average
! and determines the corresponding letter grade with
! the following table:
!
! A : average >= 90
! AB : 85 <= average < 90
! B : 80 <= average < 84
! BC : 75 <= average < 79
! C : 70 <= average < 74
! CD : 65 <= average < 69
! D : 60 <= average < 64
! F : average < 60
!
! where 'average' is the rounded average of the three
! marks. More precisely, if the average is 78.6, then it
! becomes 79 after rounding; or, if the average is 78.4,
! it becomes 78 after truncating.
! ----------------------------------------------------------
PROGRAM LetterGrade
IMPLICIT NONE
REAL :: Mark1, Mark2, Mark3
REAL :: Average
CHARACTER(LEN=2) :: Grade
READ(*,*) Mark1, Mark2, Mark3
Average = (Mark1 + Mark2 + Mark3) / 3.0
SELECT CASE (NINT(Average)) ! round Average before use
CASE (:59) ! <= 59 -------------> F
Grade = 'F '
CASE (60:64) ! >= 60 and <= 64 ---> D
Grade = 'D '
CASE (65:69) ! >= 65 and <= 69 ---> CD
Grade = 'CD'
CASE (70:74) ! >= 70 and <= 74 ---> C
Grade = 'C '
CASE (75:79) ! >= 75 and <= 79 ---> BC
Grade = 'BC'
CASE (80:84) ! >= 80 and <= 84 ---> B
Grade = 'B '
CASE (85:89) ! >= 84 and <= 89 ---> AB
Grade = 'AB'
CASE DEFAULT ! >= 90 -------------> A
Grade = 'A '
END SELECT
WRITE(*,*) 'First Mark : ', Mark1
WRITE(*,*) 'Second Mark : ', Mark2
WRITE(*,*) 'Third Mark : ', Mark3
WRITE(*,*) 'Average : ', Average
WRITE(*,*) 'Letter Grade : ', Grade
END PROGRAM LetterGrade
Click here to download this program.
97.0 90.0 94.0 First Mark : 97. Second Mark : 90. Third Mark : 94. Average : 93.6666641 Letter Grade : A
92.0 85.0 83.0 First Mark : 92. Second Mark : 85. Third Mark : 83. Average : 86.6666641 Letter Grade : AB
75.0 60.0 45.0 First Mark : 75. Second Mark : 60. Third Mark : 45. Average : 60. Letter Grade : D
In the program, REAL variable Average holds the average of the three input marks. To round the average value to be used in the SELECT CASE statement, NINT(Average) is used. Other parts are obvious.