Advertisement
axyd

Perl Grade Calculator

Sep 30th, 2017
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.96 KB | None | 0 0
  1. #########################
  2. #       PERL TIPS       #
  3. #########################
  4. =begin comment
  5. 1 WYSWYG  strings (split across multiple lines)
  6. 2 Single brackets dont process symbols (\n), just shows them
  7. 3 Variable symbols for DECLARATION
  8.     **for interpretation use $ for all***
  9.         Scalar(simple)      '$'
  10.         Array               '@'
  11.         Hash/value pairs    '%'
  12. 4 print doesnt need ()
  13. =cut
  14.  
  15.  
  16. #########################
  17. #   Grade Calculator    #
  18. #########################
  19.  
  20. use Switch;             #cpanm package
  21.  
  22. print ("\n\tEnter your score: ");
  23.  
  24. #Global variable
  25. $score = <STDIN>;       #get user input
  26. chomp $score;           #remove newline char
  27.  
  28. print "\n Your grade:  ",gradeCalc(),"\n";
  29.  
  30.  
  31. # Converts numeric score to letter grade
  32. #
  33. sub gradeCalc{
  34.     my $grade;          #local variable
  35.    
  36.     switch ($score){
  37.         case [90..100]{ $grade= "A"; }
  38.         case [80..89] { $grade= "B"; }
  39.         case [70..79] { $grade= "C"; }
  40.         case [60..69] { $grade= "D"; }
  41.         else          { $grade= "F"; }
  42.     }
  43.    
  44.     return $grade;
  45. }
  46.  
  47. <STDIN>;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement