in reply to Perl Newbie trying to figure out how to find out Median in my program

Consider that the Median of a set is the number where half of all elements of the set are smaller than that number and half of them are larger than that number.

If you have a list that is sorted, the median will be somewhere close to the middle of the list.

If the list has an odd number of elements, it will be right in the middle of the list.

If you show us your code, we can likely give better advice that is more to the point.

  • Comment on Re: Perl Newbie trying to figure out how to find out Median in my program

Replies are listed 'Best First'.
Re^2: Perl Newbie trying to figure out how to find out Median in my program
by bricksatmywindow (Initiate) on Apr 20, 2017 at 00:04 UTC

    My apologies. This is what I have so far.

    #!/usr/bin/perl use Modern::Perl; my ($total, $howmany, $largest, $smallest,$number, $average) = (0, + 0 +, 0, 0, 0, 0); print "Enter a value, negative value to end "; chomp ($number =<> ); $smallest = $number; $largest =$number; while ($number != -1) { $total += $number; $howmany += 1; $smallest = $number if $number < $smallest; $largest = $number if $number > $largest; $median = ($number, $number, $number print "Enter a value, negative value to end "; chomp ($number =<>); } if ($howmany == 0 ) { say "There were no values to process. "; } else { say "AVG: ", $total / $howmany; say "LRG: ", $largest; say "SML: ", $smallest; say "MED: ", }
      You're going to need to store all the numbers in an array, then find the median once you have them all.