Advertisement
jbonanno

Final Score

Oct 2nd, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.85 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. #Creates a function to average the test scores
  4. sub finalScore{
  5. #Creates a scalar variable of the number of test scores entered.
  6.    $n = scalar(@_);
  7.  
  8. #creates a variable of the number of test scores entered.
  9.    $total = 0;
  10.  
  11. #for each test within the array finalScore, the total is added.
  12.    foreach $test (@_){
  13.       $total += $test;
  14.    }
  15.  
  16. #The total is divided by the number of tests to get the average giving the final score.
  17.    $finalScore = $total / $n;
  18.  
  19.    print "Your final score is : $finalScore\n";
  20. }
  21.  
  22.  
  23. finalScore(86, 99, 78, 55, 100, 93, 77, 83);
  24.  
  25.  
  26. #This determines whether or not the student passed or failed the class based on the final score.
  27.  
  28. $passorfail = ($finalScore > 80 )? "You passed the class" : "You failed the class";
  29.  
  30. #This prints whether the student passes or fails the class
  31. print   "- $passorfail\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement