Example 21
We'll go through a complete example now to make sure
we've got the hang of things so far.
A company gets orders from its customers and gives a
discount of 10% on orders worth more than $200. Whatever
the total comes to, sales tax at 5% has to be added. A
typical bill, or invoice, might look like this:
value = 220.00
discount = 22.00
subtotal = 198.00
sales
tax = 9.90
total = 207.90
If the value is less than $200 then the discount
would, of course, be zero but you would still need to add
sales tax.
See your teacher now if you're not sure how this
works.
1. Design a Solution
Our first attempt is:
1. get value of order
2. calculate total
3. print invoice
[HINT: already you should see that the main program
looks like being made up of three procedures]
Step 1 is straightforward...
1.1 prompt user for
value of order
1.2 read in value of order
Step 2 is more complicated...
2.1 if value is
greater than $200
2.2 then
2.3 discount is 10% of value
2.4 else
2.5 discount is zero
2.6 subtotal is value - discount
2.7 sales tax is 5% of subtotal
2.8 total is subtotal + sales tax
Step 3 is simply
3.1 print value
3.2 print discount
3.3 print subtotal
3.4 print sales tax
3.5 print total
The complete design, then, looks like this:
|