Pizza problem:
You have been asked by the local pizza restaurant to write a program that will allow them to determine the price of the pizzas they sell. They sell two types of pizzas, the normal round pizza and Sicilian pizza (thick crust and square). They sell whole pies only but let customers determine the size. The sizes are by the whole inch and range from their 6 inch mini pizzas to their 21 inch party pizza (larger and smaller sizes are available upon request). They do not allow customers to ruin their delicious pizzas with any toppings. They determined that the best way to price their pies are by the square inch. The normal round pizzas are priced at 15 cents a square inch and the Sicilian pizza are priced at 20 cents a square inch. Lastly, if a person wants the pizza delivered a $5.00 delivery charge is added. After inputting the data they want to know what the total price of the order will be. One last thing, because of the demand for the pizzas only one pizza is allowed per customer.
Formulas:
The area of a circle is equal to 3.142 * half the size squared
(size/2)2 . The
notation to square a number is ^ (ie 5 squared would be 5 ^ 2).
For example: square inches = 3.142 * (size/2)^2
The area of a square is size squared (size2 or size * size).
Open notepad and breakdown of this problem into a problem statement:
Assumptions (scope):
Input (what's coming in):
Calculations:
Output (what's going out):
Scroll down for the answer after you try to do it yourself first
Assumptions (what is the scope):
Only one pie can be ordered at a time
Only whole pie measured by whole inches will be ordered
Price per inch for round pizza is a constant $.15
Price per inch for square pizza is a constant $.20
Delivery is a constant $5 charge
Input (What will be entered into our program):
Size of the Pie
Shape of the pie
Delivery (yes/no)
Calculations:
If Pie is square:
a. square inches = size * size
b. pie price = square inches * square price
If Pie is not square
a. square inches = 3.142 * (size/2)2
b. pie price = square inches * round price
If Delivered:
a. final price = pie price + delivery charge
Output:
The price of the order is pie price
Now you need to write the human algorithm (the simple steps
necessary to solve this problem):
Scroll down for the answer after you try to do it yourself first
Answer to the Human algorithm
Remember, we create the human algorithm from the problem statement (although we can go the other way if you find that creating the human algorithm is easier. We start out by declaring our constants (1-3), inputting our data (4-6), doing the math (7-13) then outputting the answer (14)
| Human Algorithm
1. round price = $ .15
|
Problem statement (from above) Assumptions (what is the scope):
|
Now we want to flowchart this on a piece of paper:
Scroll down for the answer after you try to do it yourself first
Flowchart
Remember we create the flow chart directly from the human
algorithm. 14 steps in the human algorithm, 14 symbols on the flowchart.
If you open your human algorithm and visual logic together on the same screen,
next to each other, the flowchart should be easy to create since we have already
solved the problem.
![]() |
Human Algorithm
1. round price = $ .15
7.
If Pie is square: 13. pie price = pie price + 5
|
Now that we have all the pieces together we just need to put them altogether into a computer program so open up html kit and lets get to work.
Scroll down for the answer after you try to do it yourself first
We type the code directly from the flowchart since we have already solved the problem. Each symbol is a line of code. We get the DIM values from each assignment (rectangle) and each input. Then we just type the line of code the symbol represents. Assignments are already in vbscript syntax, for input you just add (inputbox(...)), for output you add (document.write....)
| <script language=vbscript> Option Explicit Dim roundprice, squareprice, deliverycharge, size, shape, delivery, sqinches, pieprice 'assignments roundprice = .15 squareprice = .20 deliverycharge = 5.00 'input size = inputbox("What is the size of the pie?") shape = inputbox("Is the pie square or round?") delivery = inputbox("Will your pizza be delivered? yes/no") 'calculations If shape = "square" then sqinches = size * size pieprice= sqinches * squareprice else sqinches = 3.142 * (size/2)^2 pieprice = sqinches * roundprice end if If delivery = "yes" then pieprice = pieprice + deliverycharge end if 'output document.write "The price of the order is $" & pieprice </script> |
![]() |