Create a program that uses two parallel one-dimensional arrays. The program displays a shipping charge that is based on the number of items ordered by a customer. The shipping charge scale is shown in Figure 1 below. Store the maximum order amounts in a one dimensional int array. Store the shipping charge amounts in a parallel one dimensional int array. The program should allow the user to enter the number of items a customer ordered. It then should display the appropriate shipping charge. Use a sentinel value to stop the program. Save and then run the program. Test the program appropriately.

Min.Order Max.Order ShippingCharge
1 10 15
11 50 10
51 100 5
101 99999 0

2 answers

Here's a little perl ditty that should do the trick. Adapt to the language of choice.

my @max = (10,50,100,99999);
my @sc = (15,10,5,0);

do {
 print "enter amount ordered: ";
 my $amt = <>;
 last if $amt <= 0;
 printf "Order: %5d -- Shipping Charge: \$%d\n",$amt,pop grep($amt<$_,@sc);
}
my @max = (10,50,100,99999);
my @sc = (15,10,5,0);

do {
print "enter amount ordered: ";
my $amt = <>;
last if $amt <= 0;
printf "Order: %5d -- Shipping Charge: \$%d\n",$amt,pop grep($amt<$_,@sc);
}