# Cash Register-need help

Tell us what’s happening:
NEED HELP!
I am trying to figure out the main problem about cash register. I don’t know how to write algorithm for giving change back in certain coins and bills. That is under test 2 and 3. You can see what I have done so far but more is too difficult.
Please if anyone can help me and give more instructions I would be grateful. Thanks

``````
var payment = [
{ name: 'ONE HUNDRED', val: 100.00},
{ name: 'TWENTY', val: 20.00},
{ name: 'TEN', val: 10.00},
{ name: 'FIVE', val: 5.00},
{ name: 'ONE', val: 1.00},
{ name: 'QUARTER', val: 0.25},
{ name: 'DIME', val: 0.10},
{ name: 'NICKEL', val: 0.05},
{ name: 'PENNY', val: 0.01}
];

function checkCashRegister(price, cash, cid) {
var result = {status : "", change: []}
var change = cash - price;

var register = cid.reduce(function(acc, curr) {
acc += curr[1];
return acc;

}, 0.0);

if(register === change){
result.status = "CLOSED"
result.change = cid
return result
}
if(register < change){
result.status = "INSUFFICIENT_FUNDS"
return result
}

console.log()

// Here is your change, ma'am.

}

// Example cash-in-drawer array:
// [["PENNY", 1.01],
// ["NICKEL", 2.05],
// ["DIME", 3.1],
// ["QUARTER", 4.25],
// ["ONE", 90],
// ["FIVE", 55],
// ["TEN", 20],
// ["TWENTY", 60],
// ["ONE HUNDRED", 100]]

checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36`.

Hint: you will need to check the change you need to give back against how much you have in each value and how much a piece of that value is

So, for example if you need to give back 0.27\$ and you have two quarters and a penny (total 0.51\$) you can’t because you don’t have enough pennies (as you have 0.25 + 0.25 + 0.01 you can’t get 0.27 combining in any way - but if the change due is 0.26\$ you can give back 0.25 in quarters and 0.01 in pennies because you have enough coins)

I understand that problem, the thing is I don’t know how to write a code. I too long think about that and still have no idea how to write algorithm.

You will need to write it on your own, as this is a final project.
Try first writing pseudo code, as in the logical steps to solve the question
Try to break it down to the smallest possible steps

Think back to the Roman Numeral exercise. The concept in that exercise helped me think of ways to solve this exercise.