Advertisement
Guest User

Fungerande kod //Max

a guest
Jul 21st, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. <form action="cctest.php" method="post">
  2.     <input type="text" placeholder="1000kr" name="onethousand">
  3.     <input type="text" placeholder="500kr" name="fivehundred">
  4.     <input type="text" placeholder="200kr" name="twohundred">
  5.     <input type="text" placeholder="100kr" name="onehundred">
  6.     <input type="text" placeholder="50kr" name="fifty">
  7.     <input type="text" placeholder="20kr" name="twenty">
  8.     <input type="text" placeholder="10kr" name="ten">
  9.     <input type="text" placeholder="5kr" name="five">
  10.     <input type="text" placeholder="2kr" name="two">
  11.     <input type="text" placeholder="1kr" name="one">
  12.     <button type="submit" name="submit">Submit</button>
  13. </form>
  14.  
  15. <?php
  16.  
  17. if(isset($_POST['submit'])) {
  18.  
  19.     $billValues = array(
  20.         $_POST['onethousand'],
  21.         $_POST['fivehundred'],
  22.         $_POST['twohundred'],
  23.         $_POST['onehundred'],
  24.         $_POST['fifty'],
  25.         $_POST['twenty']
  26.     );
  27.  
  28.     $coinValues = array(
  29.         $_POST['ten'],
  30.         $_POST['five'],
  31.         $_POST['two'],
  32.         $_POST['one']
  33.     );
  34.  
  35.     $billDenomValues = array(1000, 500, 200, 100, 50, 20);
  36.     $coinDenomValues = array(10, 5, 2, 1);
  37.  
  38.     $amountOfBills = array_sum($billValues);
  39.     $amountOfCoins = array_sum($coinValues);
  40.     $valueOfBills = 0;
  41.     $valueOfCoins = 0;
  42.  
  43.     $i = 0;
  44.  
  45.     while($i < 6) {
  46.         $valueOfBills += $billValues[$i] * $billDenomValues[$i];
  47.         $i++;
  48.     }
  49.  
  50.     $i = 0;
  51.  
  52.     while($i < 4) {
  53.         $valueOfCoins += $coinValues[$i] * $coinDenomValues[$i];
  54.         $i++;
  55.     }
  56.  
  57. }
  58.  
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement