Hi there,
I don't know perl, but I do know some other languages (tested this with PHP)..
Here goes:
Code:
$i = $x;
$z = 0; //Don't know if this is the right way to declare a variable, but you get the idea
print "Multiple of fours between $x and $y are:\n";
while ($i <= $y)
{
if ($i % 4 == 0)
{
print "$i\t";
$z = $z + $i;
}
$i = $i + 1;
}
print "Sum = $z";
I declared $z before your while loop and put 'print sum' after your while loop.
You want to do it this way because the way you have it, it prints "$i (tab) Sum = $z" everytime the if-condition is true. That's why it prints "4 (tab space) Sum = 48 (tab space) Sum = 12" (it went through the if two times).
What you want to do is let it print the "Sum = $z" when it's done with the while loop.
I hope you understand what I mean, kind of a vague explanation sorry :P