Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // You can run this code at http://writecodeonline.com/php/
- $dollars = 1502;
- $cost = 3; // Dollars per chocolate
- $ratio = 3; // Wrappers to receive another chocolate
- $chocolates = $wrappers = floor($dollars / $cost);
- while ($wrappers >= $ratio)
- {
- $wrappers = $wrappers - $ratio + 1;
- $chocolates++;
- }
- echo "$" . $dollars . " gets you " $chocolates . " chocolates with " . $wrappers . " wrapper(s) and $" . $dollars % $cost . " left over.";
- // Example Output:
- // $1502 gets you 749 chocolates with 2 wrapper(s) and $2 left over.
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement