Question
Summary : You create a PHP file that will run from your local host (XAMPP) to exercise a While loop. In this exercise you are
Summary :
You create a PHP file that will run from your local host (XAMPP) to exercise a While loop. In this exercise you are going to use a while-loop to figure out how much tip ( in percentage) you can afford. See screenshot below.
Instructions:
- Create a new document using VS Code or your text editor and save this file as: yourlastname-MealsPHP.php. This file includes both HTML and PHP statements.
- Type the declaration, element, header information, and element. Use Calculating Restaurant Check as the content of the
element and tags. - In the Title type your full name
- Between the and
1. Create a new document in your text edit or using VS code save it as: yourlastname-MealPHP.php. This file contains both HTML and PHP statements.
2. Type the declaration, element, header information, and
element.3. In the Title type: "Calculating Restaurant Check as the content of the
4. Add the standard PHP delimiters to the document body:
...
?>
5. Type PHP codes to display: "Start the Calculation" and add three blank lines below this text.
6. Imagine you have certain amount of money (cast_on_hand) and order a meal (meal). You compute cost of meal (cost) by adding meal and tip (tip_percent).
7. Declare the following variables, use proper PHP syntax for declaring variables:
- cash_on_hand and assign some value to it.
- meal, and assign some value to it.
- tip_percent, and assign some value to it.
- cost, to be computed.
8. Calculate cost with a tip and store it in a variable named: cost. Cost formula is: meal + meal * (tip_percent / 100).
9. Make sure that cash is a little more than meal price. For example assign $20 for cash_on_hand and $15 for meal and 15% to tip_percent.
10. Create a while-loop that runs as long as cost is less than cash_on_hand and displays the following in each run :
I can afford a tip of 15% , for Total Cost: (34.5) such that 15% is coming from variable tip_percent and 34.5 from cost. When cost is greater than cash-on-hand, then loop stops. In each run loop displays this message and adds 1% to tip_percent until meal cost exceeds your cash_on_hand.
11 Save the document as yourlastname-MealPHP.php.
0 localhost/HW6ph Start the calculations I can afford a tip of 15%, for Total Cost: (34.5) I can afford a tip of 16%, for Total Cost: (34.8) I can afford a tip of 17%, for Total Cost: (35.1) I can afford a tip of 18%, for Total Cost: (35.4) I can afford a tip of 19%, for Total Cost: (35.7) I can afford a tip of 20%, for Total Cost: (36) I can afford a tip of 21%, for Total Cost: (36.3) I can afford a tip of 22%, for Total Cost: (36.6) I can afford a tip of 23%, for Total Cost: (36.9) I can afford a tip of 24%, for Total Cost: (37.2) I can afford a tip of 25%, for Total Cost: (37.5) I can afford a tip of 26%, for Total Cost: (37.8) I can afford a tip of 27%, for Total Cost: (38.1) I can afford a tip of 28%, for Total Cost: (38.4) I can afford a tip of 29%, for Total Cost: (38.7) I can afford a tip of 30%, for Total Cost: (39) I can afford a tip of 31%, for Total Cost: (39.3) I can afford a tip of 32%, for Total Cost: (39.6) I can afford a tip of 33%, for Total Cost: (39.9) This is end of the calculation
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started