Advertisement
axyd

Fortran Grade Calculator

Sep 15th, 2017
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. s!Grade calculator
  2. program GradeCalc
  3.     implicit none
  4.     integer :: score
  5.    
  6.     !prototype function return length
  7.     character*2 calc
  8.    
  9.     !user inputs score
  10.     write (*,*) '  Enter score: '
  11.     read (*,*) score
  12.  
  13.     !show grade
  14.     write (*,*) '    Your grade: ', calc(score)
  15.  
  16. end program GradeCalc
  17.  
  18. !converts from numerical to letter grade
  19. function calc(sco) result(gr)
  20.     implicit none
  21.  
  22.     character(*) :: gr
  23.     integer :: sco
  24.    
  25.     SELECT CASE (sco)
  26.         CASE (90:100)
  27.             gr= 'A'
  28.         CASE (80:89)
  29.             gr= 'B'
  30.         CASE (70:79)
  31.             gr= 'C'
  32.         CASE (60:69)
  33.             gr= 'D'
  34.         CASE (0:59)
  35.             gr= 'F'
  36.         CASE DEFAULT
  37.             write (*,*) '    ERROR: Invalid score '
  38.             gr= 'x'
  39.     END SELECT
  40. end function calc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement