You have been asked to write a program for the local festival of lights. Whenever a vehicle stops at the entrance of the park the user of this software must enter the type of vehicle (car, truck, bus) and then the price of admission for that vehicle will pop up on the screen. When the user clicks okay the program will ask if there's another vehicle, if there is, then the process will start all over again. The price is based upon the type of vehicle which is $5 for a car, $8 for a truck, and $25 for a bus. Once the festival is over they want to know how many of each vehicle has been admitted, the total money collected for each vehicle and the total amount collected for the day. We want to flow chart this as an If...elseIf...else logic structure but code it as a Select Case logic structure.
First Let's do the problem statement for this:
Assumptions
Given
Calculations
Output
Answer
You have been asked to write a program for the local festival of lights. Whenever a vehicle stops at the entrance the user of this software must enter the type of vehicle and the price of admission for that vehicle will pop up on the screen. When the user clicks okay the program will ask if there's another vehicle, if there is then the process will start all over again. The price for the vehicles are $5 for a car, $8 for a truck, and $25 for a bus. Once the festival is over they want a report that will show how many of each vehicle was admitted, the total money collected for each vehicle and the total amount collected for the day.
Problem Statement
Assumptions:
1. Only one vehicle will be analyzed at a time.
2. Only three types of vehicles.
3. Only daily totals are required
Given:
1. Type of Vehicle
2. Whether to process another vehicle
Calculations
If a Car then number of cars + 1
If a Truck the number of trucks + 1
If a Bus then number of buses + 1
Car receipts = number of cars * 5
Truck receipts = number of trucks * 8
Bus receipts = number of buses * 25
Total receipts = Car receipts + Truck receipts + Bus receipts
Output:
1. If a car then popup "Ask for $5"
2. If a truck then popup "Ask for $8"
3. If a bus then popup Ask for $25"
4. The total number of cars
5. The total number of trucks.
6. The total number of buses
7. The total amount of money received
Now write the human Algorithm Answer
Human Algorithm:
1. Ask what type of vehicle
2. If a car:
a. Tell them to collect $5
b. Add 1 to the car count
c. Move to line 5
3. If a truck:
a. Tell them to collect $8
b. Add 1 to the truck count
c. Move to line 5
4. If a bus:
a. Tell them to collect $25
b. Add 1 to the bus count
5. Ask if they have another vehicle, if yes move to line 1
6. Calculate money collected for cars (number of cars * 5)
7. Calculate money collected for trucks (number of trucks * 8)
8. Calculate money collected for buses (number of buses * 25)
9. Calculate grand total of money collect (money collected for cars +
trucks + buses)
10. Output the number of cars and amount of money collected for them
11. Output the number of trucks and amount of money collected for them
12. Output the number of buses and amount of money collected for them
13. Output the grand total amount of money collected
Now Create the flowchart Answer

Now Create the VB Script Answer
<script language = "vbscript">
option explicit
Dim car, carcost, cartotal, truck, truckcost, trucktotal, bus, buscost, bustotal,
typevehicle, anothervehicle, grandtotal
carcost = 5 '<--I am placing these constants into memory so it is easy to change
them later
truckcost = 8
buscost = 25
anothervehicle = "yes" '<-- This allows my loop to start without asking a
question of the user
Do While anothervehicle = "yes"
typevehicle = Inputbox("What type of vehicle? car, truck, bus...all lower
case" )
Select Case typevehicle
case "car"
'<-- "car" is compared to what is stored in the place in memory called
typevehicle
msgbox("Ask for $" & carcost)
car = car + 1
case "truck"
msgbox("Ask for $" & truckcost)
truck = truck + 1
case "bus"
msgbox("Ask for $" & buscost
bus = bus + 1
case else
msgbox("You
didn't type in car, truck or bus! remember all lower case")
end select
anothervehicle = inputbox("Do you want to add another vehicle? yes/no")
'<-- This is where we can stop the looping if they type "no".
Loop
' <--- Sends us back to the Do While line of code to determine if we loop again
or go on to the next line of code.
cartotal = car * carcost
trucktotal = truck * truckcost
bustotal = bus * buscost
Grandtotal = cartotal + trucktotal + bustotal
Document.write "The total number of cars is " & car & ". The total amount of
money collected is $" & cartotal
Document.write "<p>The total number of trucks is " & truck & ". The total amount
of money collected is $" & trucktotal
Document.write "<p>The total number of cars is " & bus & ". The total amount of
money collected is $" & bustotal
Document.write "<p>The total amount of money is $" & Grandtotal
</script>