Hello pcoady,

First, please edit the title of your post to remove the <p> tags.

Now to the assignment. Two preliminary matters:

  1. Your specification says: “until a negative number is entered.” But you are testing on only one negative number, namely -1. What if the user enters -2? You can fix this by changing the while condition to:

    while ( $number >= 0 )
  2. The closing brace is missing from the final else block.

How to get the script to record the largest and smallest numbers? As an alternative to the solution proposed by Loops, you can treat the first user-entered number differently from all the others:

while ($number >= 0) { $total += $number; $howmany++; if ($howmany == 1) { $largest = $number; $smallest = $number; } else { $largest = $number if $number > $largest; $smallest = $number if $number < $smallest; } print "Please enter a number or -1 to end: "; chomp($number = <>); }

— a variation on the solution given by Anonymous Monk.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: I am stuck on how to print the largest and smallest numbers from user inputted values. Any help is appreciated. by Athanasius
in thread I am stuck on how to print the largest and smallest numbers from user inputted values. Any help is appreciated. by pcoady

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.