programming-examples/perl/Statement/Average-sales problem with sentinel-controlled repetition.pl
2019-11-15 12:59:38 +01:00

20 lines
475 B
Perl

$total = 0;
$weekCounter = 0;
print "Enter sales for week or enter quit: ";
chomp( $sales = <STDIN> );
until ( $sales eq 'quit' ) {
$weekCounter++;
$total += $sales;
print "Enter sales for week or enter quit: ";
chomp( $sales = <STDIN> );
}
if ( $weekCounter != 0 ) {
$average = $total / $weekCounter;
print "\nSales averaged $average computers per week.\n";
}
else {
print "\nNo sales figures were entered.\n";
}