Perl Question hoping you can solve?

xSirPotsAlotx

New member
I need this program to accept an infinite amount of numbers instead of just a set amount the user enters. Say after they typed in -1 how an I do this? I have it asking for the number of items but I went them to be able to do it how many times they want

her is my code:

#!/usr/bin/perl


# get array size
print ("How many items?\n");
$size = <STDIN> ;
chomp ($size);

# get array values
for ($x=0; $x<$size; $x++)
{
print ("Enter number\n");
$val = <STDIN> ;
chomp ($val);
$data[$x] = $val;
}

# print array values
print ("Here is what you entered: \n");
for ($x=0; $x<$size; $x++)
{
print ("$data[$x]\n");
}


#Printing the Largest Number
print "The largest number is $sorted[$size-1]\n";

#Printing the Smallest Number
print "The largest number is $sorted[0]\n";
 
Back
Top