# This is pseudocode. It is mostly in English. # You have to translate it into Perl. # # Here are the variables you need: # # data (an array with the numbers) # sorted data (an array with the sorted numbers) # number (the number you are reading from the user; a scalar) # number of items # sum (a scalar, holds the total of all the numbers) # average (a scalar) # median (a scalar) # percentage (how far above or below the average a score is; scalar) # item (a scalar used as a loop variable) # # read in the data prompt for a number read number and chomp it while (number != -1) { if (number > 0) { use push to add the number to the end of the data array } else { output an error message; the number must be positive } prompt for a number read number and chomp it } number of items = scalar(@data array) if (number of items is greater than zero) { # calculate the average set sum to zero for each item in the data array { add item to sum } average = sum / number of items # calculate the median # remember to use the sorted data array in the formula! sorted data array = sort(data array) if (number of items % 2 == 1) { use formula in the assignment to calculate median for odd number of items } else { use formula in the assignment to calculate median for even number of items } output the average, properly labeled output the median, properly labeled # now print out the scores and their relation to the average print "Value % above/below average\n"; # the heading for each item in the data array { if (item is greater than average) { percent = 100 * (item - average) / average; print "$item $percent% above\n"; } elsif (item is less than average) { percent = 100 * (average - item) / average; print "$item $percent% below\n"; } else { print "$item 0% exactly average\n"; } } } else { output a message that says no data was entered }