🔒 Closed PHP

Status
Not open for further replies.
Philippine currency is broken down into 1000, 500, 100, 50, 20, 10, 5 and 1 peso coin. Write a PHP script that would accept an integer amount in peso and output the smallest bills and coins that would add up to that amount. Output the result using input boxes and marked then as read-only.

Eto yung code ko:
____________

<!DOCTYPE html>
<html>
<body>

<?php

function countCurrency($amount)
{
$notes = array(1000 , 500, 100, 50, 20, 10, 5, 1);
$noteCounter = array(0, 0, 0, 0, 0, 0, 0, 0, 0);

for ($i = 0; $i < 9; $i++)
{
if ($amount >= $notes[$i]){
$noteCounter[$i] = intval ($amount / $notes[$i]);
$amount = $amount - $noteCounter[$i] * $notes[$i];
}
}

echo ("Enter Amount: 3998 "."<br> \n");
for ($i = 0; $i < 9; $i++)
{
if ($noteCounter[$i] != 0){
echo ($notes[$i] . "bills : " . $noteCounter[$i] . "<br> \n");
}
}
}

$amount = 3998;
countCurrency($amount);

?>

</body>
</html>
 
Kasi yan yung output ng code mo, wala naman mali sa code mo, pero di yan yung sagot sa problem mo kung ang gusto mong mangyari ay lahat ng notes na less than sa input amount ay may value.

Kung icocompute mo manually malalaman mo kung bakit.
Code:
Amount: 3998

3998 / 1000 = 3
3998 - (3 * 1000) = 998

998 / 500 = 1
998 - (1 * 500) = 498

498 / 100 = 4
498 - (4 * 100) = 98

98 / 50 = 1
98 - (1 * 50) = 48

48 / 20 = 2
48 - (2 * 20) = 8

8 / 5 = 1
8 - (1 * 5) = 3

3 / 1 = 3
3 - (1 * 3) = 0
 
Kasi yan yung output ng code mo, wala naman mali sa code mo, pero di yan yung sagot sa problem mo kung ang gusto mong mangyari ay lahat ng notes na less than sa input amount ay may value.

Kung icocompute mo manually malalaman mo kung bakit.
Code:
Amount: 3998

3998 / 1000 = 3
3998 - (3 * 1000) = 998

998 / 500 = 1
998 - (1 * 500) = 498

498 / 100 = 4
498 - (4 * 100) = 98

98 / 50 = 1
98 - (1 * 50) = 48

48 / 20 = 2
48 - (2 * 20) = 8

8 / 5 = 1
8 - (1 * 5) = 3

3 / 1 = 3
3 - (1 * 3) = 0
ayun nasagot na ni idol haha
 
Status
Not open for further replies.

About this Thread

  • 3
    Replies
  • 2K
    Views
  • 3
    Participants
Last reply from:
Misanthropy

Trending Topics

Online now

Members online
1,213
Guests online
1,184
Total visitors
2,397

Forum statistics

Threads
2,272,112
Posts
28,940,270
Members
1,237,996
Latest member
tachyon96
Back
Top