axyd icon

Fortran Grade Calculator

axyd | PRO | 09/15/17 10:53:51 PM UTC | 0 ⭐ | 10797 👁️ | Never ⏰ | []
Fortran |

720 B

|

None

|

0 👍

/

0 👎

s!Grade calculator
program GradeCalc
    implicit none
    integer :: score
    
    !prototype function return length
    character*2 calc
    
    !user inputs score
    write (*,*) '  Enter score: '
    read (*,*) score
 
    !show grade
    write (*,*) '    Your grade: ', calc(score)
 
end program GradeCalc
 
!converts from numerical to letter grade
function calc(sco) result(gr)
    implicit none
 
    character(*) :: gr
    integer :: sco
    
    SELECT CASE (sco)
        CASE (90:100)
            gr= 'A'
        CASE (80:89)
            gr= 'B'
        CASE (70:79)
            gr= 'C'
        CASE (60:69)
            gr= 'D' 
        CASE (0:59)
            gr= 'F'
        CASE DEFAULT
            write (*,*) '    ERROR: Invalid score '
            gr= 'x'
    END SELECT
end function calc

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎