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