Hi all,
I am stuck on an assignment for school and would really appreciate any help or suggestions.
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.
Calculate cost with a tip and store it in a variable named: cost. Cost formula is: meal + meal * (tip_percent / 100).
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.
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 iteration, loop displays this message and adds 1% to tip_percent until meal cost exceeds your cash_on_hand.
This is what I have so far:
$cash_on_hand = 35;
$meal = 25;
$tip_percent = 10
$cost = $meal + $meal * ($tip_percent / 100);
$cash_on_hand = 35; while($cash_on_hand <= 35) { echo "I can afford a tip of $tip_percent%, for Total Cost: $cost <br/>"; $tip_percent++; }
I am not sure what I am doing wrong. Thanks for the help!