Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('THAO', 1000);
- define('PUNCH', 500);
- define('SO', 100);
- define('HAMSA', 50);
- define('BAO', 20);
- define('KINDE', 10);
- define('KOBOLE', 5);
- define('BOB', 1);
- function calculateQuotientAndRemainder($dividend, $divisor)
- {
- if ($divisor == 0) {
- throw new InvalidArgumentException("Error: Division by zero is not allowed.");
- }
- $quotient = (int)($dividend / $divisor);
- $remainder = $dividend % $divisor;
- return array('quotient' => $quotient, 'remainder' => $remainder);
- }
- function getMoney($totalAmount)
- {
- if ($totalAmount <= 0) {
- throw new InvalidArgumentException("Error: Money should be greater than zero!");
- }
- $denominations = [THAO, PUNCH, SO, HAMSA, BAO, KINDE, KOBOLE, BOB];
- $result = array();
- foreach ($denominations as $denomination) {
- if ($totalAmount >= $denomination) {
- $result[$denomination] = (int)($totalAmount / $denomination);
- $totalAmount %= $denomination;
- }
- }
- return $result;
- }
- function display($result, $totalAmount)
- {
- $display = "Amount: $totalAmount" . PHP_EOL;
- foreach ($result as $denomination => $quantity) {
- $display .= "$quantity notes of $denomination" . PHP_EOL;
- }
- return $display;
- }
- $money = 2035;
- $result = getMoney($money);
- echo display($result, $money);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement