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