R rakhistha Eternal Poster Established Joined Nov 2, 2014 Posts 1,634 Reaction 300 Points 428 Age 36 Apr 26, 2021 #1 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.. Attachments You do not have permission to view the full content of this post. Log in or register now.
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..
H HH_PRINCE Honorary Poster Apr 26, 2021 #2 Trace muna lang ts, may binago na ako dyan. Tanong ka lang kung may question ka <?php function type($amount) { if ($amount >= 20) { return "peso Bills"; } else if ($amount < 20 && $amount >= 1) { return "peso Coins"; } else { return "cents"; } } function countCurrency($amount) { $notes = [1000, 500, 100, 50, 20, 10, 5, 1, 0.50, 0.25, 0.10, 0.05, 0.01]; $noteCounter = []; $totalNotes = count($notes); // count notes using greedy approach for ($i = 0; $i < $totalNotes; $i++) { $nc = intval(round($amount / $notes[$i], 2)); array_push($noteCounter, $nc); $amount = $amount - $nc * $notes[$i]; } // Print notes echo "Currency Denomination" . "<br><br>"; for ($i = 0; $i < $totalNotes; $i++) { echo $notes[$i] . " " . type($notes[$i]) . " : " . $noteCounter[$i] . "<br>"; } } // Driver Code $amount = 1375.29; countCurrency($amount); ?> Last edited: Apr 26, 2021
Trace muna lang ts, may binago na ako dyan. Tanong ka lang kung may question ka <?php function type($amount) { if ($amount >= 20) { return "peso Bills"; } else if ($amount < 20 && $amount >= 1) { return "peso Coins"; } else { return "cents"; } } function countCurrency($amount) { $notes = [1000, 500, 100, 50, 20, 10, 5, 1, 0.50, 0.25, 0.10, 0.05, 0.01]; $noteCounter = []; $totalNotes = count($notes); // count notes using greedy approach for ($i = 0; $i < $totalNotes; $i++) { $nc = intval(round($amount / $notes[$i], 2)); array_push($noteCounter, $nc); $amount = $amount - $nc * $notes[$i]; } // Print notes echo "Currency Denomination" . "<br><br>"; for ($i = 0; $i < $totalNotes; $i++) { echo $notes[$i] . " " . type($notes[$i]) . " : " . $noteCounter[$i] . "<br>"; } } // Driver Code $amount = 1375.29; countCurrency($amount); ?>
R rakhistha Eternal Poster Established Apr 26, 2021 TS TS #4 HH_PRINCE meron bang mali..bakit kaya hindi ko mainsert ung isang code..ok naman ung syntax..kaso sa variable declaration tama naman.. <?php function countCurrency($amount) { $notes = [1000, 500, 100, 50, 20, 10, 5, 1, 0.50, 0.25, 0.10, 0.05, 0.01]; $noteCounter = []; $totalNotes = count($notes); // count notes using greedy approach for ($i = 0; $i < $totalNotes; $i++) { $nc = intval(round($amount / $notes[$i], 2)); array_push($noteCounter, $nc); $amount = $amount - $nc * $notes[$i]; } // Print notes echo nl2br('<h3>Amount in Pesos:'.$amount."\n"."\n"); //eto ang dinagdag ko..kaso naging ganun ung amount. echo "Currency Denomination" . "<br><br>"; for ($i = 0; $i < $totalNotes; $i++) { echo $notes[$i] . " " . type($notes[$i]) . " : " . $noteCounter[$i] . "<br>"; } } // Driver Code $amount = 1375.29; //pwed po edit nalang dito ung amount. countCurrency($amount); function type($amount) { if ($amount >= 20) { return "peso Bills"; } else if ($amount < 20 && $amount >= 1) { return "peso Coins"; } else { return "cents"; } } ?> Attachments You do not have permission to view the full content of this post. Log in or register now.
HH_PRINCE meron bang mali..bakit kaya hindi ko mainsert ung isang code..ok naman ung syntax..kaso sa variable declaration tama naman.. <?php function countCurrency($amount) { $notes = [1000, 500, 100, 50, 20, 10, 5, 1, 0.50, 0.25, 0.10, 0.05, 0.01]; $noteCounter = []; $totalNotes = count($notes); // count notes using greedy approach for ($i = 0; $i < $totalNotes; $i++) { $nc = intval(round($amount / $notes[$i], 2)); array_push($noteCounter, $nc); $amount = $amount - $nc * $notes[$i]; } // Print notes echo nl2br('<h3>Amount in Pesos:'.$amount."\n"."\n"); //eto ang dinagdag ko..kaso naging ganun ung amount. echo "Currency Denomination" . "<br><br>"; for ($i = 0; $i < $totalNotes; $i++) { echo $notes[$i] . " " . type($notes[$i]) . " : " . $noteCounter[$i] . "<br>"; } } // Driver Code $amount = 1375.29; //pwed po edit nalang dito ung amount. countCurrency($amount); function type($amount) { if ($amount >= 20) { return "peso Bills"; } else if ($amount < 20 && $amount >= 1) { return "peso Coins"; } else { return "cents"; } } ?>
H HH_PRINCE Honorary Poster Apr 26, 2021 #5 mag-declare ka ng variable to store yung original amount kasi modified na ang amount na variable. mas mabuting mag "<br>" kana lang rin ts para wala ka nang tatawagin na function echo lang naman yan.
mag-declare ka ng variable to store yung original amount kasi modified na ang amount na variable. mas mabuting mag "<br>" kana lang rin ts para wala ka nang tatawagin na function echo lang naman yan.
P PHC_Jayvee nakatapos din sa research😂🤣 Apr 27, 2021 #7 PHP: <?php $total = 2644.67; function cointype($n){ if($n >= 20) return "bills"; if($n >= 1 && $n <= 10) return "coins"; if($n >= 0.1 && $n <= 0.5) return "cents"; if($n == 0.05) return "centavos"; if($n == 0.01) return "centavo"; } function get($n){ global $total; $type = cointype($n); if($total > $n){ echo "${n} ${type}: ". floor($total / $n)."<br />"; $total = fmod($total, $n); }else{ echo "${n} ${type}: 0<br />"; } } $denom = array(1000, 500, 100, 50, 20, 10, 5, 1, 0.50, 0.25, 0.10, 0.05, 0.01); foreach($denom as $denoms){ get($denoms); } try lang ito nagawa ko pang exercise lang bale yung idea ay divide and get the whole number then get yung remainder and set Last edited: Apr 27, 2021
PHP: <?php $total = 2644.67; function cointype($n){ if($n >= 20) return "bills"; if($n >= 1 && $n <= 10) return "coins"; if($n >= 0.1 && $n <= 0.5) return "cents"; if($n == 0.05) return "centavos"; if($n == 0.01) return "centavo"; } function get($n){ global $total; $type = cointype($n); if($total > $n){ echo "${n} ${type}: ". floor($total / $n)."<br />"; $total = fmod($total, $n); }else{ echo "${n} ${type}: 0<br />"; } } $denom = array(1000, 500, 100, 50, 20, 10, 5, 1, 0.50, 0.25, 0.10, 0.05, 0.01); foreach($denom as $denoms){ get($denoms); } try lang ito nagawa ko pang exercise lang bale yung idea ay divide and get the whole number then get yung remainder and set
R rakhistha Eternal Poster Established Apr 27, 2021 TS TS #8 Maraming salamat sir..mas konti ung code..maraming salamat sir..
R rakhistha Eternal Poster Established Apr 27, 2021 TS TS #9 Graduate ako ng 2008 batch..pero shaks..etong coding tlga nahihirapan ako..hai..not a programmer tlga..im more on the cisco part..
Graduate ako ng 2008 batch..pero shaks..etong coding tlga nahihirapan ako..hai..not a programmer tlga..im more on the cisco part..
R rakhistha Eternal Poster Established Apr 27, 2021 TS TS #11 Basic lang din naman alam ko sir..mahal exam sir..hehehe..