| Cost | 10% | 15% | 20% |
|---|---|---|---|
| 10.00 | 1.00 | 1.50 | 2.00 |
| 20.00 | 2.00 | 3.00 | 4.00 |
| 30.00 | 3.00 | 4.50 | 6.00 |
| 40.00 | 4.00 | 6.00 | 8.00 |
| 50.00 | 5.00 | 7.50 | 10.00 |
| 60.00 | 6.00 | 9.00 | 12.00 |
| 70.00 | 7.00 | 10.50 | 14.00 |
| 80.00 | 8.00 | 12.00 | 16.00 |
| 90.00 | 9.00 | 13.50 | 18.00 |
| 100.00 | 10.00 | 15.00 | 20.00 |
echo '<table width="200" border="1"><tr><th scope="col">Cost</th><th scope="col">10%</th><th scope="col">15%</th><th scope="col">20%</th></tr>';
$cost=10;
while($cost<=100) {
if($cost<100) $space=" "; else $space="";
echo '<tr><td>'.$space.number_format($cost,2).'</td>';
for($per=.10;$per<=.20;$per+=.05) {
$tip=$cost*$per;
if($tip<10) $space=" "; else $space="";
echo '<td>'.$space.number_format($tip,2).'</td>';
} //each percentage
echo '</tr>'; //end the row
$cost+=10;
}
echo '</table>';
Note: is a non-breaking space.
Experiment: This script used a for and a while loop, but it could have been written with any of the types of loops. Try writing it another way, then try creating a completely different table.