開発環境
- OS X Lion - Apple(OS)
- Apache (Web Server)
- PHP (サーバーサイドプログラミング言語)
- TextWrangler(Text Editor) (BBEditの無料機能制限版、light版)
『初めてのPHP5』 (David Sklar 著、 桑村 潤 翻訳、 廣川 類 翻訳、 オライリー・ジャパン、2005年、ISBN978-4-87311-257-2)の5章(関数)5.6(演習問題)3を解いてみる。
3.
出力結果
I can afford a tip of 11% (30) I can afford a tip of 12% (30.25) I can afford a tip of 13% (30.5) I can afford a tip of 14% (30.75)
確認
コード(TextWrangler)
<pre> <?php $cash_on_hand = 31; $meal = 25; $tax = 10; $tip = 10; while(($cost = restaurant_check($meal,$tax,$tip)) < $cash_on_hand){ $tip++; print "I can afford a tip of $tip% ($cost)\n"; } function restaurant_check($meal,$tax,$tip){ $tax_amount = $meal * ($tax / 100); $tip_amount = $meal * ($tip / 100); return $meal + $tax_amount + $tip_amount; } ?> </pre>
HTMLソース
<pre> I can afford a tip of 11% (30) I can afford a tip of 12% (30.25) I can afford a tip of 13% (30.5) I can afford a tip of 14% (30.75) </pre>
0 コメント:
コメントを投稿