Class Notes: MOnday September 9, 2013
New Commands:
chop
chomp
<STDIN>
while(boolean_expression )
{
body_of_loop
}
#!/usr/bin/perl
use strict;
# we convert from euros/liter to $/gallon
my $europe;
my $american;
my $euroToDollar=1.33;
my $litersPerGallon=3.8;
my $startValue=15;
my $stopValue=8;
my $number=0;
while($startValue < $stopValue )
{
print "Start is $startValue stop is $stopValue\n";
print "Please enter price in euros per liter ";
chomp($europe=);
# we'll do this in 2 steps. First convert to $ per liter
# 1 euro= $1.33
$american=$europe*$euroToDollar; # this is now dollars per liter
# now we convert to gallons. 3.8 liters to a gallon
$american=$american* $litersPerGallon;
print "Dollars per gallon is $american\n";
$startValue=$startValue+1;
}
# Lets add 1+2+3+ +22+23
$startValue=1;
$stopValue=24;
while($startValue < $stopValue)
{
$number=$number+$startValue;
$startValue=$startValue+1;
}
print "The total is $number\n";
Homework:
calculate the following series:
1 + 1/2 + 1/4 + 1/8 + 1/16 +
1 + 1/2 + 1/3 + 1/4 + 1/5 +
Calculate both series for 1000, 10000, 100000 , 1000000 terms