Coding Flowchart
What follows is a Logical Flow of the PHP code, written in plain English, for the cash register program.
First rename the $_GET or $_POST variables. We do this to make them easier to work with in the code.
Note: Chkdisc is a special case, because it may be passed as a NULL (does not exist) value. Write code to set the chkdisc to a value > 0 if it is null.
Use a decimal, not a percent, when setting checkdisc
As of this point, you have 4 variables you are now working with:
$meal
$disc_perc (the decimal value, actually, of the discount)
$tax
$tip
Next, we use a SWITCH CASE statement to assign the value of the price to the meal. For example, if the meal chosen was SPAGHETTI, set the price to $5 or $14.50 or whatever you choose.
Note, we are “switching case,” i.e., checking the value of, the variable $meal
Next, we calculate the DOLLAR AMOUNT of the discount, using the value of the $disc_perc that we calculated earlier.
Note, the discount amount is calculated by multiplying:
$meal * $disc_perc
Next, we use simple math to calculate the BILL
Note: use $bill as the variable for holding the bill amount
Lastly, we print the variables onto the page using the ECHO statement.
The only catch here is the number format function, which I will show you, to print only two decimal places!
Wednesday, May 8, 2013
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.