- Joined
- Nov 2, 2014
- Posts
- 1,627
- Reaction
- 295
- Points
- 426
- Age
- 36
Pahelp naman po sa code. Sa image po ang target kong output. Kaso pag run ko ng code, ung mga need lang na denomination ang nagaappear.
<?php
function countCurrency($amount)
{
$notes = array(1000, 500, 100, 50, 20, 10, 5, 1, 0.50, 0.25, 0.10, 0.05, 0.01);
$noteCounter = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
// count notes using greedy approach
for ($i = 0; $i < 13; $i++)
{
if ($amount >= $notes[$i])
{
$noteCounter[$i] = intval($amount / $notes[$i]);
$amount = $amount - $noteCounter[$i] * $notes[$i];
}
}
// Print notes
echo nl2br("Currency Denomination"."\n"."\n");
for ($i = 0; $i < 13; $i++)
{
if ($noteCounter[$i] != 0)
{
echo nl2br($notes[$i] . " peso Bills : " . $noteCounter[$i] . "\n");
}
}
}
// Driver Code
$amount = 1375.29;
countCurrency($amount);
?>
pahelp po sa code..salamat..
<?php
function countCurrency($amount)
{
$notes = array(1000, 500, 100, 50, 20, 10, 5, 1, 0.50, 0.25, 0.10, 0.05, 0.01);
$noteCounter = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
// count notes using greedy approach
for ($i = 0; $i < 13; $i++)
{
if ($amount >= $notes[$i])
{
$noteCounter[$i] = intval($amount / $notes[$i]);
$amount = $amount - $noteCounter[$i] * $notes[$i];
}
}
// Print notes
echo nl2br("Currency Denomination"."\n"."\n");
for ($i = 0; $i < 13; $i++)
{
if ($noteCounter[$i] != 0)
{
echo nl2br($notes[$i] . " peso Bills : " . $noteCounter[$i] . "\n");
}
}
}
// Driver Code
$amount = 1375.29;
countCurrency($amount);
?>
pahelp po sa code..salamat..
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.