Duplicate Question
The question on this page has been marked as a duplicate question.
Original Question
Write a program that allows the user to input a total dollar amount for an online shopping order and computes and outputs the s...Asked by Anonymous
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
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
Answers
Answered by
Steve
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...
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...
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.