Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- > ATM has enough amount to pay
- > amount would be anything between 1-50000
- > notes 10, 20, 50, 100, 500, 2000
- pay with minimun notes
- print: which note how many times used
- ex: payable amout 110
- notes: 10, 20, 50
- solution: 50 * 2 + 10 = 110
- 50: 2,
- 10: 1
- total notes used = 3
- */
- function getAmt(amt) {
- var note5, note10, note20, note50 = 0
- if(amt >= 50)
- {
- console.log("Now amt: " + amt);
- note50 = amt / 50
- note50 = Math.round(note50)
- amt -= note50 * 50
- }
- if(amt >= 20)
- {
- console.log("Now amt: " + amt);
- note20 = amt / 20
- note20 = Math.round(note20)
- amt -= note20 * 20
- }
- if(amt >= 10)
- {
- console.log("Now amt: " + amt);
- note10 = amt / 10
- note10 = Math.round(note10)
- amt -= note10 * 10
- }
- if(amt >= 5)
- {
- console.log("Now amt: " + amt);
- note5 = amt / 5
- note5 = Math.round(note5)
- amt -= note5 * 5
- }
- console.log("Now amt should 0: " + amt);
- console.log(`note5: ${note5}, note10: ${note10}, note20: ${note20}, note50: ${note50}`);
- }
- getAmt(105)
Add Comment
Please, Sign In to add comment