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. $bedrag = floatval($argv[1]);
  4. $rest = 0;if (!$bedrag) {
  5.     exit("Geen wisselgeld");
  6. }define("GELDEENHEDEN", array(50, 20, 10, 5, 2, 1));
  7. $restbedrag = $bedrag;
  8. foreach (GELDEENHEDEN as $valuta) {
  9.     if ($restbedrag >= $valuta) {
  10.         $aantal = floor($restbedrag / $valuta);
  11.         $restbedrag = $restbedrag % $valuta;
  12.         echo "$aantal x $valuta euro" . PHP_EOL;
  13.     }
  14.     
  15. $centen = $bedrag;
  16. }foreach (GELDEENHEDEN as $cent) {
  17.     if ($centen >= $cent / 100) {
  18.         $aantal = floor($centen / ($cent / 100));
  19.         $centen = $centen % $cent;
  20.         $centen = round(fmod($centen, ($cent / 100)));
  21.         echo "$aantal x $cent cent" . PHP_EOL;
  22.     }
  23. }?>
  24.  
  25.  
File Description
  • wisselgeld
  • PHP Code
  • 11 Oct-2021
  • 677 Bytes
You can Share it: