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. echo "restant = " . $rest . PHP_EOL;
  25. $rest = $rest * 100;
  26. if ($rest >= 1) {
  27.     foreach (GELDEENHEDEN as $centen) {
  28.         $aantal_centen = floor($rest / $centen);
  29.         $rest = fmod($rest, $centen);
  30.         $centen = round($centen);
  31.         if ($aantal_centen >= 0) {
  32.             echo $aantal_centen . " x " . $centen . " cent" . PHP_EOL;
  33.         }
  34.     }
  35. }
  36.  
  37.  
File Description
  • wisselgeld
  • PHP Code
  • 13 Oct-2021
  • 954 Bytes
You can Share it: