in reply to New Perl user - help with my homework
print "Please enter a number: \n"; my ($limit)= <STDIN>; chomp $limit; my $sum = 1; my @array = (); for (my $i=1; $i<=$limit; $i+=2) { $sum += 2 push(@array,'1') } my $average = $sum/scalar(@array); print "$average\n";
after the push (which means you need the aforementioned semicolon) to see what is going on:print "i: $i, sum: $sum, array: @array, scalar: ", scalar(@array), "\n +";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: New Perl user - help with my homework
by Eardrum (Initiate) on Dec 24, 2018 at 14:53 UTC |