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. ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. error_reporting(E_ALL);
  5.  
  6. define("GELDEENHEDEN", ["50", "20", "10", "5", "2", "1"]);
  7.  
  8. echo(round(0.50) . "<br>");
  9. echo(round(0.20) . "<br>");
  10. echo(round(0.10) . "<br>");
  11. echo(round(0.05) . "<br>");
  12. echo(round(0.02) . "<br>");
  13. echo(round(0.01));
  14.  
  15. $input = $argv[1];
  16. $rest = (float)$input;
  17.  
  18. echo "restant = " . $rest . PHP_EOL;
  19. if (!$input) {
  20.     exit("Geen wisselgeld") . PHP_EOL;
  21. } else {
  22.     foreach (GELDEENHEDEN as $valuta) {
  23.         if ($rest >= $valuta) {
  24.             $aantal_valuta = floor($rest / $valuta);
  25.             $rest = fmod($rest, $valuta);
  26.             echo $aantal_valuta . " x " . $valuta . " euro" . PHP_EOL;
  27.             echo $rest . PHP_EOL;
  28.         }
  29.     }
  30. }
  31. echo "restant = " . $rest . PHP_EOL;
  32. $rest = $rest * 100;
  33. if ($rest >= 1) {
  34.     foreach (GELDEENHEDEN 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.09 Kb
You can Share it: