...

View Full Version : Beginner needing help



Rashimana
11-11-2012, 07:15 PM
Here is my code


<?php
$hamburger = 4.95;
$choc_mlk_shk = 1.95;
$cola = 0.85;
$food = 2 * $hamburger + $choc_mlk_shk + $cola;
$tax = $food * 0.075;
$tip = $food * 0.16;
$total = $food + $tax + $tip;
printf ("%1d %9s at \$%.2f each: \$%.2f\n", 2, 'Hamburgers', $hamburger, 2 * $hamburger);
printf ("%1d %9s at \$%.2f each: \$%.2f\n", 1, 'Chocolate Milk Shake', $choc_mlk_shk, $choc_mlk_shk);
printf ("%1d %9s at \$%.2f each: \$%.2f\n", 1, 'Cola', $cola, $cola);
printf ("%25s: \$%.2f\n", 'Food and Drink Total', $food);
printf ("%25s: \$%.2f\n", 'Post Tax Total', $food + $tax);
printf ("%25s: \$%.2f\n", 'Total', $food + $tax + $tip);
?>

I understand just about everything here. My only question is with %25s and %9s.

I know that the s is meaning string and gathering the string information, but what are the numbers for?

Nile
11-12-2012, 01:50 PM
Check out example #7 here

http://www.php.net/manual/en/function.sprintf.php



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum