![]() |
Example 21We'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
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
[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
Step 2 is more complicated... 2.1 if value is greater than $200
Step 3 is simply 3.1 print value
The complete design, then, looks like this:
|
1. get value of order
|
1.1 prompt user for value of order
2.1 if value is greater than $200
3.1 print value
|
|
PROGRAM orders; {to print out an invoice} VAR
{procedure get_value goes here} {procedure calc_total goes here} {procedure invoice goes here} BEGIN
{main program starts here}
|
If you've got this far and understood the course material then, once again, you've done well. There's more to learn, of course, but you've done much of the hard work!
|
© 1998 John Brewer |