Write a program that allows the user to input a total dollar amount for an

online shopping order and computes and outputs the shipping cost based
on the following schedule:
Order Total Ship within USA Ship to Canada
Less than $50.00 $6.00 $8.00
$50.01–$100.00 $9.00 $12.00
$100.01–$150.00 $12.00 $15.00
Over $150.00 Free Free

1 answer

here's a little perl program which should do the job. You can probably adapt it to the language of your choice.

my @rates = [
{amount=>150,us=>0,canada=>0},
{amount=>100,us=>12,canada=>15},
{amount=>50,us=>9,canada=>12},
{amount=>0,us=>6,canada=>8}
];

while (1) {
my $amount = <STDIN>;
last unless $amount > 0;
foreach (@rates) {
next unless $amount > $_->{amount};
printf "Order: \$%4.2f\nUS: \$%4.2f\nCanada: \$%4.2f\n",@{$_}{qw(us canada)};
}
}

If you don't know perl, now's your chance to learn it...