Gentlemen:
Regarding the Cash Register Project,
You should, by now, have the form finished and should be working on Page 2 of the assignment. Page 2 contains all the code.
Remember, the goal is to calculate the bill for the restaurant meal:
Here's a tip (Ha, get it? A "tip?").
OK, Several tips:
discount amount = (mealprice * discount decimal)
Discount decimial means a percentage (i.e., 10%) expressed as a decimal (i.e., 0.10)
bill = (mealprice - discount amount) + tax + tip.
Showing posts with label code. Show all posts
Showing posts with label code. Show all posts
Tuesday, February 23, 2010
Make Progress Today
Labels:
cash register,
check box,
code,
discount,
form fields,
forms,
php,
text fields
Monday, February 22, 2010
Code Flowchart for Cash Reg!
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!
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, January 27, 2010
Friday, January 22, 2010
Hello World!
Subscribe to:
Posts (Atom)


