Nasty Cash Register

So I was bored and decided to re-take infamous Cash Register:

And I remember that last time there was a bug that drove me crazy and now it struck me again:

So, if status of my drawer is CLOSED, my change would be whole cid with bunch of zeros, but if status is OPEN I would give proper change… THIS IS CREEPY!
But if you still wanna go this road, I have suggestion! In case of INSUFFICIENT_FUNDS let’s require student to draw a pony :wink:

            .''
  ._.-.___.' (`\
 //(        ( `'
'/ )\ ).__. ) 
' <' `\ ._/'\
   `   \     \
1 Like

What do you think is a bug?

checkCashRegister(19.5, 20, [
  ["PENNY", 0.5],
  ["NICKEL", 0],
  ["DIME", 0],
  ["QUARTER", 0],
  ["ONE", 0],
  ["FIVE", 0],
  ["TEN", 0],
  ["TWENTY", 0],
  ["ONE HUNDRED", 0]
])` 
should return: 
{status: "CLOSED", change: [["PENNY", 0.5]]}`

instead got:
{status: "CLOSED", change: [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]}

i was crazy to finish this one but i managed to solve it finally there is no bug
hints
eliminate unwanted changes from drawer that are greater than change i due
and
if change is greater than element

change= change-element 

else if change is less than element

 change=change%element 

hint try to understand this code

if(change>=array[i][1])
   {
   need.push(array[i][1]);
   change=change-array[i][1]
   }
   else if(change<array[i][1]){
   need.push(change-change%array[i][0])
   change=change%array[i][0]
   }

Hey @kumenger!
Thanks for your hint :wink: You code is a bit out of my frame of understanding and I think you will have to make some ugly things right after the if statement to make it work, but I think I got it!

I’ll be nice and friendly and give you HINT back :slight_smile:
HINT: If your FCC tests pass, it doesn’t mean there are no bugs, my friend. For example, FCC solution fails this case:

const cid = [["PENNY",1], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 1], ["ONE", 1], ["FIVE", 5], ["TEN", 10], ["TWENTY", 20], ["ONE HUNDRED", 0]];
checkCashRegister(3, 3.01, cid);

If you post your solution, I’m almost certain that I’ll find failing test for your code, but that’s not even a topic of this post, you see…

I feel that you didn’t quite understand me. Functions, like checkCashRegister have to be predictable and declarative. checkCashRegister, for example, must output 3 things:

  1. Can I manage input transaction?
  2. If yes, the amount of change I have to give back?
  3. Am I able to proceed to the next transaction?

Amount (value) of change should not be dependent on OPEN/CLOSED status because it’s not related to current transaction, but next.

1 Like


i will see it and reposet where is the problem