Lesson Six, Part II, Select Case Problem

Original Problem: You have been asked to write a program for a plumbing supply warehouse.  The have several types of tubing that then sell for different prices.  The following is the price list based upon a linear foot of tubing:  Plastic = .30; PVC = .60; aluminum = .75; copper = 1.00; Stainless Steel = 1.25; bronze = 1.35; gold = 5.50.  They want to see at the end of the program what type pipe was ordered, how many feet were ordered (only whole feet will be input) and the total amount of the order.

Our client was very happy with our plumbing problem we completed in the last exercise.  Now they want to expand it's scope.  After we get the total amount of the order they want you to calculate and display the tax and the grand total of the order.  They want you to figure out the tax based upon the zip code of where the sale will be made in Charleston (The business is a large truck full of pipe that travels around Charleston selling pipe).   Because of recently passed sales tax legislation each municipality can establish it's own local sales tax rate to fund its school system.  The rates are as follows:  29401, 29402, 29402 and 29409 are taxed at 7 1/2 percent.   29411, 29412, 29414, and 29416 are taxed at 8 percent.  29418, 29419, 29424 are all taxed at 8 1/2 percent.  Any other zip code will be taxed at the state sales tax amount of 6 1/2 percent.

Create a problem statement:
Answer

 

 

 

 

 

 

 

 

 

 

Problem Statement:

Assumptions:
Only Plastic, PVC,  Stainless Steel, bronze, and  gold tubing available
Only one order at a time
only feet not inches are evaluated

Input:
Type of tubing:  Plastic, PVC,  Stainless Steel, bronze, copper, and  gold
Number of feet of tubing
zipcode

Calculations:
Based upon type of pipe:
    If  totalOrder = Plastic Length * .30
    IF  totalOrder =  PVC Length * .60
    IF totalOrder =  aluminum Length * .75
    IF  totalOrder = copper Length * 1.00
    IF  totalOrder = Stainless Steel Length * 1.25
    IF  totalOrder = bronze Length *1.35
    IF  totalOrder = gold Length * 5.50
Based upon the zipcode:
    If zipcode is 29401 or 29402 or 29403 or 29409 then tax = totalorder * .075
    If zipcode is 29411 or 29412 or 29414 or 294016 then tax = totalorder * .08
    If zipcode is 29418 or 29419 or 29424 then tax = totalorder * .085
    Any other zipcode then tax = totalorder * .065
Grandtotal = totalorder + tax

Output
type pipe
how many feet
total amount of the order.
tax
GrandTotal

Create a human algorithm:
Answer

 

 

 

 

 

 

 

 

 

Human Algorithm:

1.  Input the type of tubing
2.  Input the number of feet of tubing
2.5 Input the zip code
3.  Based upon the Type of Tubing do the following calculation
    a. Plastic then totalcost = Length * .30
    b. PVC then totalcost =  Length * .60
    c. Aluminum then totalcost =  Length * .75
    d.  Copper then totalcost =  Length * 1.00
    e.  Stainless Steel then totalcost =  Length * 1.25
    f.  Bronze then totalcost =  Length *1.35
    g.  Gold then totalcost =  Length * 5.50
3.5.  Based upon the zipcode do the following calculations:
    a. If zipcode is 29401 or 29402 or 29403 or 29409 then tax = totalorder * .075
    b. If zipcode is 29411 or 29412 or 29414 or 294016 then tax = totalorder * .08
    c.  If zipcode is 29418 or 29419 or 29424 then tax = totalorder * .085
Any other zipcode then tax = totalorder * .065

Grandtotal = totalorder + tax

4 Output Type of Pipe
5. Output number of feet
6.  Output total cost
7.  Output the tax
8.  Output the grandtotal

Now create a flowchart:
answer

 

 

 

 

 

 

 

 

 

 

 

 

Flowchart: Remember, you can't do select case using visual logic so this is If....elseif....else

When testing multiple values in the case structure you use this syntax:

Dim Name

Name = "Tom"

Select Case Name

Case "Bill", "Tom"
Document.write "Wow, you are a good looking guy"

Case "Betty", "Jill"

Document.write "Wow, you are a good looking girl"

End Select

Now code the flowchart above:
answer

 

 

 

 

 

 

 

 

 

 

 

 

 

Code:
<Script language = "vbscript">
Dim tubetype, NumFeet, TotalOrder, zipcode, grandtotal, tax

tubetype = inputbox("What type of tube? plastic, PVC, aluminum, bronze, Stainless Steel, copper, gold")
NumFeet = inputbox("How many feet do you want?")
zipcode = inputbox("What is the zipcode")

Select Case tubetype

Case "plastic"
TotalOrder = NumFeet * .30

Case "PVC"
TotalOrder = NumFeet * .60

Case "aluminum"
TotalOrder = NumFeet * .75

Case "bronze"
TotalOrder = NumFeet * 1.00

Case "Stainless Steel"
TotalOrder = NumFeet * 1.25

Case "copper"
TotalOrder = NumFeet * 1.50

Case "gold"
Totalorder = NumFeet * 5.50

Case Else
MsgBox(" Type does not Match")
End Select

Select Case zipcode

Case "29401", "29402", "29403", "29409"
    tax = Totalorder * .075

Case "29411", "29412","29414", "29416"
    tax = Totalorder * .08

Case "29418", "29419", "29424"
    tax = Totalorder * .085

Case Else
    tax = Totalorder * .065
End Select

grandtotal = Totalorder + tax

Document.write "<p>Type of pipe " & tubetype
Document.write "<p>Total number of feet is " & Numfeet
Document.write "<p>Total order is $" & TotalOrder
document.write "<p>the tax is " & tax
Document.write "<p>Grand Total is $" & grandtotal

</Script>