sanjay555

ATM.js

Jan 23rd, 2018
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.   > ATM has enough amount to pay
  3.   > amount would be anything between 1-50000
  4.   > notes 10, 20, 50, 100, 500, 2000
  5.  
  6.   pay with minimun notes
  7.  
  8.   print: which note how many times used
  9.  
  10.   ex: payable amout 110
  11.   notes: 10, 20, 50
  12.  
  13.   solution: 50 * 2 + 10 = 110
  14.  
  15.   50: 2,
  16.   10: 1
  17.  
  18.   total notes used = 3
  19.  
  20.  
  21. */
  22.  
  23.  
  24. function getAmt(amt) {
  25.   var note5, note10, note20, note50 = 0
  26.  
  27.   if(amt >= 50)
  28.   {
  29.     console.log("Now amt: " + amt);
  30.     note50 = amt / 50
  31.     note50 = Math.round(note50)
  32.     amt -= note50 * 50
  33.   }
  34.   if(amt >= 20)
  35.   {
  36.     console.log("Now amt: " + amt);
  37.     note20 = amt / 20
  38.     note20 = Math.round(note20)
  39.     amt -= note20 * 20
  40.   }
  41.   if(amt >= 10)
  42.   {
  43.     console.log("Now amt: " + amt);
  44.     note10 = amt / 10
  45.     note10 = Math.round(note10)
  46.     amt -= note10 * 10
  47.   }
  48.   if(amt >= 5)
  49.   {
  50.     console.log("Now amt: " + amt);
  51.     note5 = amt / 5
  52.     note5 = Math.round(note5)
  53.     amt -= note5 * 5
  54.   }
  55.   console.log("Now amt should 0: " + amt);
  56.  
  57.  
  58. console.log(`note5: ${note5}, note10: ${note10}, note20: ${note20}, note50: ${note50}`);
  59. }
  60.  
  61. getAmt(105)
Add Comment
Please, Sign In to add comment