jbonanno icon

Final Score

jbonanno | PRO | 10/02/17 05:17:43 AM UTC | 0 ⭐ | 319 👁️ | Never ⏰ | []
Perl |

850 B

|

None

|

0 👍

/

0 👎

#!/usr/bin/perl
 
#Creates a function to average the test scores
sub finalScore{
#Creates a scalar variable of the number of test scores entered.
   $n = scalar(@_);
 
#creates a variable of the number of test scores entered.
   $total = 0;
 
#for each test within the array finalScore, the total is added.
   foreach $test (@_){
      $total += $test;
   }
 
#The total is divided by the number of tests to get the average giving the final score.
   $finalScore = $total / $n;
 
   print "Your final score is : $finalScore\n";
}
 
 
finalScore(86, 99, 78, 55, 100, 93, 77, 83);
 
 
#This determines whether or not the student passed or failed the class based on the final score. 
 
$passorfail = ($finalScore > 80 )? "You passed the class" : "You failed the class";
 
#This prints whether the student passes or fails the class
print   "- $passorfail\n";

Comments