Average-sales problem with sentinel-controlled repetition : Until « Statement « Perl






Average-sales problem with sentinel-controlled repetition

  
  
$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";
}

   
    
  








Related examples in the same category

1.A program that uses the until statement.
2.Controlling Loop Flow
3.Looping Until
4.The until Loop
5.The until modifier repeatedly executes the second expression as long as the first expression is false.
6.The until statement
7.Use until to read user input
8.Using until with print statement
9.until statement
10.until with continue
11.until with diamond operator
12.until with integer