# Cash register- what is the difference between the first 2 tests

Hello,
I am slowly making progress on my understanding of the cash register problem. But I have two questions:

1- The test number 1 and test number 2 look exactly the same to me (same price, same cash, same amount in the drawer (cid) (see picture attached).

What I am really not understanding is how can the input the same but the output are different
Test 1 output is : should return an object
Test 2 output is: should return {status: “OPEN”, change: [[“QUARTER”, 0.5]]}

2- How is it that we are not told anywhere to test if price > cash? And if price > cash what should the function be returning?

I have been enjoying this problem so much but I am thinking that there is a major thing I am missing in my reasoning and understanding of the problem.
I hope one of you will make me understand why I have the wrong thinking about all of this and point me to the right direction.

Thank you in advance everyone.

Sorry all,
I have the answer to my first question.
It is because
{status: “OPEN”, change: [[“QUARTER”, 0.5]]}
is the object that should be the output.
The first test just tests that the output is an object,
the second test shows you the object.

Can someone confirm this for me? Or should I just go back and read about what is an object?

Well it seems like 1 mystery is solved now, I just need an answer for my question2.

Thank you all in advance!

1 Like

I believe you’re right. Just two different “tests” for the same input.

Thank you very much for stopping by and for confirming I am still sane
Any idea on my question 2 about the checkCashRegister function? Why does it seems important to me to make sure that price < cash even though I do not see that check being made in any solution I have seen on the forum?

It doesn’t matter if `price` is larger than `cid`. It only matters if the change owed is larger than `cid`. If you pay \$20 for something with a price of \$19.95 I can still make change even if my drawer only contains a nickel.

the algorithm goal is to calculate the change due to the client when the payment is made, if not enough cash is given the payment can’t be made and so the algorithm is useless

If it was a real cash register program there would probably be a check that would stop the request for change due if the client is not giving enough money, and it would not be run also if `cash` equals `price`

Thank you so much for stopping by to answer my question!
I was not actually worrying about price > cid or changedOwed > cid, I know that for this case the function must return:

``````{
Return {status: "INSUFFICIENT_FUNDS", change: []} if cash-in-drawer is less than the change due, or if you cannot return the exact change.
}
``````

What I was worried about is how is it that nowhere in the function do we have to check if price > cash ? I was expecting the problem to tell us to write something so that the function would not execute or there would be some kind of error output if price > cash.

But the reply of ieahleen made me understand that this is not a full on cash register program this is just a function for training on algorithmic thinking. In a cash register program you would check that price < cash before and the function would execute only if (price < cash).

Thank you very much for your response and your support ArielLeslie, it feels good to get response and know that we are not alone on the journey.
Now go and change the world!
Happy coding!

Thank you very much for your answer! Your answer is clear and straight to the point. The cash register function can only happen if there is payment, and by definition there can only be payment if cash >= price. The test for payment would happen independently from the function itself (e.g it is not because I do not have a driver’s license or gas money that I can not build a car. Building a car or a function is independent on wether all the conditions for the car or function to be used are met… little digression).

The goal of the problem is to find how to give cash back.
I am now dividing the problem in smaller pieces:

• The cash register needs to know how much money in \$value is to be given back (cash - price = change)
• The cash register needs to know how much cash in drawer in \$value and in bills and coins is available to give back (cid).
• If change > cid - return insufficient fund
• If change === cid - return status closed
-if cid > change. I need to create and use a function that compares the \$value of change and the \$value of cid and the coins and bills in cid (currency) - ( 2 cases )
case1- currency “matches” change I can organize the currency in proper order to give back the change and return - {status: “OPEN”, change: […]}
case2- currency can not “match” change with the right number of bills and coins and the function returns (insufficient fund).

I still have a lot of work in designing the function that would compare the change in \$value to the coins and bills in cid but I am way closer now than where I was yesterday.

Thank you so very much for your help and your time in stopping by.
Please do not hesitate to let me know if I am heading in a totally wrong direction
Happy coding! and one more time: a big thank you !

1 Like

you are going in the right direction, and this will be your biggest challenge

to make it easier for you, I will also provide a source that would explain some behaviour which will cause the most bugs even if you have correct logic (I mean, have you ever tried to see what’s the result for `0.1 + 0.2`? Let me tell you, unfortunately it is not 0.3) (there is also an advice on how to deal with currencies in the video)

1 Like

Thank you for letting me know that I am not running towards the wall, and thank you very much for the heads up about the currency issue. Also, I
love Computerphile videos. Those guys go very deep but they explain the concepts super clearly so that even simple minded people like me get it
I am going to work on my solution now. Thank you very much for your help.
I hope that your code will make a difference in people’s lives. You certainly made a difference in mine!
Happy coding!