*JavaScript Algorithms and Data Structures Projects: Cash Register

wow, your’e stuck on it for like two months, i somehow managed to do it in 1 day kinda first try (spoiler!!! my post). so:
for safety problems, convert every value to cents (*100), you won’t regret it.
first, you need to define a change, which is the cash-price (and you did).

second, define a value array (how many dollars is everything, remember multiplying the values).

third, you need to check the total cash available in your register that will use the values that are under or equal your change (if your change is a quarter but you have one whole dollar you can’t return),define a function for that.

fourth, if your total cash that matches is less than the change u can’t return it, thus return the needed thing (insufficient funds).

fifth, if your total cash is exactly the change, just return CID.

sixth, if your total cash is more than the change, start iterating through CID values (from biggest), if your change is more or equal to the value and your CID is more than the value (if you have 0 at CID you can’t get money from it) then subtract the values from both your change and CID value, to print out the change do CID_before - CID_after and set it to the CID value.

don’t forget to return CID values divided by 100!! (make functions for both the multiplication and division)

hope i helped, if something isn’t clear your’e welcome :slight_smile:

1 Like