PDA

View Full Version : What is wrong here?


Buckster_uk
12-10-2005, 06:32 PM
Write a for-loop that, for an unordered list of any randomly chosen 10 integers in the range 1 to 100, will remove all integers greater than 50 and, at the end, print in ascending numerical order the shortened list of integers in the range 1 to 50.

Code...

#!/usr/bin/perl

for ($count=1; $count<11; $count++)

{

$random = int( rand(100)) + 1;

$list = ($random < 51);

print "$list\n";

}

FishMonger
12-10-2005, 06:47 PM
$list = ($random < 51);

That's a true/false test.

If $random is less than 51, $list is set to 1 (true).
If $random is not less than 51, $list is set to 0 (false). (or an empty string)

Since this is a homework assignment, I can't provide you with the proper solution, but hopefully that info should be enough for you to figure out what needs to be done.