Created
April 24, 2017 01:33
-
-
Save zr0n/34b23bca30ab6c617952229b723a6aac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function calc_troco($pago, $conta){ | |
$nota = array('100', '50', '10', '5', '1'); | |
$centavos = array('50', '10', '5','1'); | |
$troco = $pago - $conta; | |
$vlr = $troco; | |
for($i = 0; $i <= 4; $i++){ | |
$ct = floor($vlr / $nota[$i]); // calculando a qtde de notas | |
if ($ct) { | |
$result = $ct. " nota(s) de R$". $nota[$i]." Reais<br>"; | |
$vlr = $vlr % $nota[$i]; // sobra | |
echo $result; | |
} | |
} | |
} | |
calc_troco(20, 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment