What's new

O

kiplog

Grasshopper
Joined
Oct 25, 2021
Posts
13
Reaction
0
Points
15
PROBLEM: 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.
1635596692974.png

PHP:
<!DOCTYPE html>
<html>
<body>

<form action = "" method = "post">

    Enter Amount : <input type="text" name="currency">
    <input type="submit" value="GENERATE" name="amount"/>
</form>

      <?php
      if(isset($submit['currency']))
  { 
      $currency = $submit['amount'])
      $one_thou = $amount/1000;
      $one_thour = fmod($amount,1000);
      $five_hun = $one_thour/500;
      $five_hunr = fmod($one_thour,500);
      $one_hun = $five_hunr/100;
      $one_hunr = fmod($five_hunr,100);
      $fifty = $one_hunr/50;
      $fifty_r = fmod($one_hunr,50);
      $twenty = $fifty_r/20;
      $twenty_r = fmod($fifty_r,20);
      $ten = $twenty_r/10;
      $ten_r = fmod($twenty_r,10);
      $five = $ten_r/5;
      $five_r = fmod($ten_r,5);
      $one = $five_r/1;


      echo "<br> P1000 Bills: ".$one_thou;
      echo "<br> P500 Bills: ".$five_hun;
      echo "<br> P100 Bills: ".$one_hun;
      echo "<br> P50 Bills: ".$fifty;
      echo "<br> P20 Bills: ".$twenty;
      echo "<br> P10 Coins: ".$ten;
      echo "<br> P5 Coins: ".$five;
      echo "<br> P1 Coins: ".$one;

      }
      ?>

</body>
</html>
 

Attachments

1635600847770.png


PHP:
<!DOCTYPE html>
<html>
    <body>
        <table>
            <form action="bills.php" method="POST">
            <tr>
                <td>Enter amount:</td>
                <td><input type="text" name="amount" value="<?=isset($_POST['amount']) ? $_POST['amount'] : ''?>"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Generate"></td>
            </tr>
            </form>
            
            <?php
            
                $numberOfBills = array(0, 0, 0, 0, 0, 0, 0, 0);
                $bills = array(1000, 500, 100, 50, 20, 10, 5, 1);
                
                if(isset($_POST['amount']))
                {
                    $amount = $_POST['amount'];
                    
                    for ($i = 0; $i < 8; $i++)
                    {
                        $numberOfBills[$i] = intval($amount / $bills[$i]);
                        $amount = fmod($amount, $bills[$i]);
                    }
                }
                
                for ($i = 0; $i < 8; $i++)
                {
            ?>
            <tr>
                <td><b><?=$bills[$i]?> Bills</b></td>
                <td><input type="text" value="<?=isset($numberOfBills[$i]) ? $numberOfBills[$i] : ''?>" readonly></td>
            </tr>
                
            <?php } ?>
          
          
        </table>
    </body>
</html>
 

Attachments

Pag coins pala:

PHP:
<!DOCTYPE html>
<html>
    <body>
        <table>
            <form action="bills.php" method="POST">
            <tr>
                <td>Enter amount:</td>
                <td><input type="text" name="amount" value="<?=isset($_POST['amount'])?$_POST['amount']:''?>"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Generate"></td>
            </tr>
            </form>

            <?php
                if(isset($_POST['amount']))
                {
                    $amount = $_POST['amount'];
                
                    $bills_1000 = intval($amount / 1000);
                    $amount = fmod($amount, 1000);
                    
                    $bills_500 = intval($amount / 500);
                    $amount = fmod($amount, 500);
                    
                    $bills_100 = intval($amount / 100);
                    $amount = fmod($amount, 100);
                    
                    $bills_50 = intval($amount / 50);
                    $amount = fmod($amount, 50);
                    
                    $bills_20 = intval($amount / 20);
                    $amount = fmod($amount, 20);
                    
                    $coins_10 = intval($amount / 10);
                    $amount = fmod($amount, 10);
                    
                    $coins_5 = intval($amount / 5);
                    $amount = fmod($amount, 5);
                    
                    $coins_1 = intval($amount / 1);
                }
            ?>   
            
            <tr>
                <td><b>P1000 Bills</b></td>
                <td><input type="text" value="<?=isset($bills_1000)?$bills_1000:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P500 Bills</b></td>
                <td><input type="text" value="<?=isset($bills_500)?$bills_500:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P100 Bills</b></td>
                <td><input type="text" value="<?=isset($bills_100)?$bills_100:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P50 Bills</b></td>
                <td><input type="text" value="<?=isset($bills_50)?$bills_50:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P20 Bills</b></td>
                <td><input type="text" value="<?=isset($bills_20)?$bills_20:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P10 Coins</b></td>
                <td><input type="text" value="<?=isset($coins_10)?$coins_10:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P5 Coins</b></td>
                <td><input type="text" value="<?=isset($coins_5)?$coins_5:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>1 Coins</b></td>
                <td><input type="text" value="<?=isset($coins_1)?$coins_1:''?>" readonly></td>
            </tr>
 
        </table>
    </body>
</html>
 
Pag coins pala:

PHP:
<!DOCTYPE html>
<html>
    <body>
        <table>
            <form action="bills.php" method="POST">
            <tr>
                <td>Enter amount:</td>
                <td><input type="text" name="amount" value="<?=isset($_POST['amount'])?$_POST['amount']:''?>"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Generate"></td>
            </tr>
            </form>

            <?php
                if(isset($_POST['amount']))
                {
                    $amount = $_POST['amount'];
               
                    $bills_1000 = intval($amount / 1000);
                    $amount = fmod($amount, 1000);
                   
                    $bills_500 = intval($amount / 500);
                    $amount = fmod($amount, 500);
                   
                    $bills_100 = intval($amount / 100);
                    $amount = fmod($amount, 100);
                   
                    $bills_50 = intval($amount / 50);
                    $amount = fmod($amount, 50);
                   
                    $bills_20 = intval($amount / 20);
                    $amount = fmod($amount, 20);
                   
                    $coins_10 = intval($amount / 10);
                    $amount = fmod($amount, 10);
                   
                    $coins_5 = intval($amount / 5);
                    $amount = fmod($amount, 5);
                   
                    $coins_1 = intval($amount / 1);
                }
            ?>  
           
            <tr>
                <td><b>P1000 Bills</b></td>
                <td><input type="text" value="<?=isset($bills_1000)?$bills_1000:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P500 Bills</b></td>
                <td><input type="text" value="<?=isset($bills_500)?$bills_500:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P100 Bills</b></td>
                <td><input type="text" value="<?=isset($bills_100)?$bills_100:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P50 Bills</b></td>
                <td><input type="text" value="<?=isset($bills_50)?$bills_50:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P20 Bills</b></td>
                <td><input type="text" value="<?=isset($bills_20)?$bills_20:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P10 Coins</b></td>
                <td><input type="text" value="<?=isset($coins_10)?$coins_10:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P5 Coins</b></td>
                <td><input type="text" value="<?=isset($coins_5)?$coins_5:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>1 Coins</b></td>
                <td><input type="text" value="<?=isset($coins_1)?$coins_1:''?>" readonly></td>
            </tr>
 
        </table>
    </body>
</html>
Salamat lods hanapin ko na lang yung error, ayaw kasi mag appear yung number sa baba
 
Pag coins pala:

PHP:
<!DOCTYPE html>
<html>
    <body>
        <table>
            <form action="bills.php" method="POST">
            <tr>
                <td>Enter amount:</td>
                <td><input type="text" name="amount" value="<?=isset($_POST['amount'])?$_POST['amount']:''?>"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Generate"></td>
            </tr>
            </form>

            <?php
                if(isset($_POST['amount']))
                {
                    $amount = $_POST['amount'];
               
                    $bills_1000 = intval($amount / 1000);
                    $amount = fmod($amount, 1000);
                   
                    $bills_500 = intval($amount / 500);
                    $amount = fmod($amount, 500);
                   
                    $bills_100 = intval($amount / 100);
                    $amount = fmod($amount, 100);
                   
                    $bills_50 = intval($amount / 50);
                    $amount = fmod($amount, 50);
                   
                    $bills_20 = intval($amount / 20);
                    $amount = fmod($amount, 20);
                   
                    $coins_10 = intval($amount / 10);
                    $amount = fmod($amount, 10);
                   
                    $coins_5 = intval($amount / 5);
                    $amount = fmod($amount, 5);
                   
                    $coins_1 = intval($amount / 1);
                }
            ?>  
           
            <tr>
                <td><b>P1000 Bills</b></td>
                <td><input type="text" value="<?=isset($bills_1000)?$bills_1000:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P500 Bills</b></td>
                <td><input type="text" value="<?=isset($bills_500)?$bills_500:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P100 Bills</b></td>
                <td><input type="text" value="<?=isset($bills_100)?$bills_100:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P50 Bills</b></td>
                <td><input type="text" value="<?=isset($bills_50)?$bills_50:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P20 Bills</b></td>
                <td><input type="text" value="<?=isset($bills_20)?$bills_20:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P10 Coins</b></td>
                <td><input type="text" value="<?=isset($coins_10)?$coins_10:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>P5 Coins</b></td>
                <td><input type="text" value="<?=isset($coins_5)?$coins_5:''?>" readonly></td>
            </tr>
            <tr>
                <td><b>1 Coins</b></td>
                <td><input type="text" value="<?=isset($coins_1)?$coins_1:''?>" readonly></td>
            </tr>
 
        </table>
    </body>
</html>
naayos ko na po salamat ulit...yung file name lang pala magkaiba kasi yung pagkasave ko kaya ayaw mag run
 

Similar threads

Back
Top