<?php
$inputValue = floatval(trim(fgets(STDIN)))*100;
echo $inputValue;
$notas = [
10000=>"100.00",
5000=>"50.00",
2000=>"20.00",
1000=>"10.00",
500=>"5.00",
200=>"2.00",
];
$moedas=[
100=>"1.00",
50=>"0.50",
25=>"0.25",
10=>"0.10",
5=>"0.05",
1=>"0.01"
];
echo "NOTAS:" . PHP_EOL;
foreach($notas as $centavo => $nota)
{
$valor = intdiv($inputValue,$centavo);
echo $valor . " nota(s) de R$ " . $nota . PHP_EOL;
$inputValue = $inputValue%$centavo;
}
echo "MOEDAS:" . PHP_EOL;
foreach($moedas as $centavo => $moeda)
{
$valor = intdiv($inputValue,$centavo);
echo $valor . " moeda(s) de R$ " . $moeda . PHP_EOL;
$inputValue = $inputValue%$centavo;
}
function calcularCedulas(int &$valor, array $itens, string $tipo): void
{
echo $tipo . ":\n";
foreach ($itens as $item) {
$quantidade = intdiv($valor, $item);
printf(
"%d %s(s) de R$ %.2f\n",
$quantidade,
strtolower(substr($tipo, 0, -1)),
$item / 100
);
$valor %= $item;
}
}
$valor = floatval(trim(fgets(STDIN))) * 100;
echo $valor;
$notas = [10000, 5000, 2000, 1000, 500, 200];
$moedas = [100, 50, 25, 10, 5, 1];
calcularCedulas($valor, $notas, "NOTAS");
calcularCedulas($valor, $moedas, "MOEDAS");
To embed this project on your website, copy the following code and paste it into your website's HTML: