Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. <?php
  2. function calc_troco($pago, $conta){
  3.  
  4. $nota = array('100', '50', '10', '5', '1');
  5. $centavos = array('50', '10', '5','1');
  6. $troco = $pago - $conta;
  7. $vlr = $troco;
  8. for($i = 0; $i <= 4; $i++){
  9. $ct = floor($vlr / $nota[$i]); // calculando a qtde de notas
  10. if ($ct) {
  11. $result = $ct. " nota(s) de R$". $nota[$i]." Reais<br>";
  12. $vlr = $vlr % $nota[$i]; // sobra
  13. echo $result;
  14. }
  15. }
  16. }
  17. calc_troco(20, 5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement