Advertisement
Guest User

Untitled

a guest
Jan 6th, 2024
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | None | 0 0
  1. <?php
  2.  
  3. define('THAO', 1000);
  4. define('PUNCH', 500);
  5. define('SO', 100);
  6. define('HAMSA', 50);
  7. define('BAO', 20);
  8. define('KINDE', 10);
  9. define('KOBOLE', 5);
  10. define('BOB', 1);
  11.  
  12. function calculateQuotientAndRemainder($dividend, $divisor)
  13. {
  14.     if ($divisor == 0) {
  15.         throw new InvalidArgumentException("Error: Division by zero is not allowed.");
  16.     }
  17.  
  18.     $quotient = (int)($dividend / $divisor);
  19.     $remainder = $dividend % $divisor;
  20.  
  21.     return array('quotient' => $quotient, 'remainder' => $remainder);
  22. }
  23.  
  24. function getMoney($totalAmount)
  25. {
  26.     if ($totalAmount <= 0) {
  27.         throw new InvalidArgumentException("Error: Money should be greater than zero!");
  28.     }
  29.  
  30.     $denominations = [THAO, PUNCH, SO, HAMSA, BAO, KINDE, KOBOLE, BOB];
  31.     $result = array();
  32.  
  33.     foreach ($denominations as $denomination) {
  34.         if ($totalAmount >= $denomination) {
  35.             $result[$denomination] = (int)($totalAmount / $denomination);
  36.             $totalAmount %= $denomination;
  37.         }
  38.     }
  39.  
  40.     return $result;
  41. }
  42.  
  43. function display($result, $totalAmount)
  44. {
  45.     $display = "Amount: $totalAmount" . PHP_EOL;
  46.  
  47.     foreach ($result as $denomination => $quantity) {
  48.         $display .= "$quantity notes of $denomination" . PHP_EOL;
  49.     }
  50.  
  51.     return $display;
  52. }
  53.  
  54. $money = 2035;
  55. $result = getMoney($money);
  56.  
  57. echo display($result, $money);
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement