Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: I am stuck on how to print the largest and smallest numbers from user inputted values. Any help is appreciated.

by AnomalousMonk (Archbishop)
on Nov 20, 2014 at 13:51 UTC ( [id://1107928]=note: print w/replies, xml ) Need Help??


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

As long as List::Util is being brought into play, why not use sum() as well as min() and max()? Just push entries to an array, say @numbers, as long as conditions for continued entry are met, then, after a test for no numbers at all having been entered,
    print 'The average of the numbers was ', sum(@numbers) / @numbers;
    print 'The largest number was ',  max @numbers;
    print 'The smallest number was ', min @numbers;
(Admittedly, this approach may not be appropriate for homework.)

Replies are listed 'Best First'.
Re^3: I am stuck on how to print the largest and smallest numbers from user inputted values. Any help is appreciated.
by parv (Parson) on Nov 20, 2014 at 22:19 UTC

    Why even specify the list twice? Make it an odd count(-.

    require List::MoreUtils ; printf "min: %f ; max : %f\n" , List::MoreUtils::minmax @num ;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1107928]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-28 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found