CS 29
40 pts., Feb. 27
For each problem, design pseudo-code, flowchart, or a perl program to solve it. If you are stuck on either of the problems let me know and I will suggest alterations to the problem(s) which you may work on for partial credit.
Since I did flowcharts in class, I'll give the perl code here.
#!/usr/contrib/bin/perl -w
$count = 2;
while ($count <= 20)
{
print "$count\n";
$count = $count + 3;
}
exit 0;
#!/usr/contrib/bin/perl -w
$sum = 0;
print "Enter a 0 to quit.\n\n";
print "Enter a number: ";
$data = <STDIN>;
while ($data != 0)
{
if ($data > 0)
{
$sum = $sum + $data;
}
else
{
print "Don't do that!\n";
}
print "Enter a number: ";
$data = <STDIN>;
}
print "The sum of the positive numbers is: $sum.\n";
exit 0;