Yeah, this is a tough one - a lot of people get stopped up by this one. I remember that I struggled with it for a while.
Are the instructions confusing? Sometimes looking at the tests help. The second test says:
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]])should return
{status: “OPEN”, change: [[“QUARTER”, 0.5]]}` .
So, it’s saying that if we call the function with:
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]])
That means a bill of 19.5 ($19.50) and they give 20 (presumable a $20 bill) and the cash register starts out with:
[["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]
then…
So that is the set up, you need to take that information, and do the calculations for what change you are going to give and return what change you are going to give them, in the form of:
{status: "OPEN", change: [["QUARTER", 0.5]]}
In other words, you are going to give them $0.50 in quarters.
What is the aim?
Described above.
And what are we supposed to do with the cid?
That tells you how much money the store has in the cash register (cash in drawer) before the transaction.
Are we supposed to convert it [cid] to dollars? If so then what is the use of it after that ?
That is the issue. If you just convert it to a total dollar figure, how would you know if you have $10 in pennies or quarters?
How do I find the change?
How do humans do it? That is the point - to convert human thinking into a computer algorithm. If you were at the register, the bill was $19.50 and someone handed you a $20, what would be your thought process? Could you explain a simple process to a child? Maybe the child isn’t good at intuitive thinking but is very good at following simple instructions. Could you come up with a series of steps for them to do this?
I’m not trying to avoid your question, I’m trying to steer you in the right direction.