wisselgeld - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of wisselgeld.php

  1. <?php
  2.  
  3. define("GELDEENHEDENEURO", ["50", "20", "10", "5", "2", "1"]);
  4.  
  5. $input = $argv[1];
  6. $rest = (float)$input;
  7.  
  8. echo "restant = " . $rest . PHP_EOL;
  9. if (!$input) {
  10.     exit("Geen wisselgeld") . PHP_EOL;
  11. } else {
  12.     foreach (GELDEENHEDENEURO as $valuta) {
  13.         if ($rest >= $valuta) {
  14.             $aantal_valuta = floor($rest / $valuta);
  15.             $rest = fmod($rest, $valuta);
  16.             echo $aantal_valuta . " x " . $valuta . " euro" . PHP_EOL;
  17.             echo $rest . PHP_EOL;
  18.         }
  19.     }
  20. }
  21.  
  22. define("GELDEENHEDENCENT", ["50", "20", "10", "5", "2", "1"]);
  23.  
  24. $centen = round(0.50);
  25. $centen = round(0.20);
  26. $centen = round(0.10);
  27. $centen = round(0.05);
  28. $centen = round(0.02);
  29. $centen = round(0.01);
  30.  
  31. echo "restant = " . $rest . PHP_EOL;
  32. $rest = $rest * 100;
  33. if ($rest >= 1) {
  34.     foreach (GELDEENHEDENCENT as $centen) {
  35.         $aantal_centen = floor($rest / $centen);
  36.         $rest = fmod($rest, $centen);
  37.         $centen = round($centen);
  38.         if ($aantal_centen >= 0) {
  39.             echo $aantal_centen . " x " . $centen . " cent" . PHP_EOL;
  40.         }
  41.     }
  42. }
  43.  
  44.  
File Description
  • wisselgeld
  • PHP Code
  • 13 Oct-2021
  • 1.05 Kb
You can Share it: