10-18-2015 12:47 PM
Hi altenbach
Could you please explain yourself more?
If I were to use a single Q&R in a for loop what would be the y input in the Q&R? It is changing 100, to 25 to 10.. etc
Here's my code. I used blackburnite's solution and it works perfectly well
10-18-2015 12:52 PM - edited 10-18-2015 12:55 PM
Here's what I would do. Fully scalable (e.g. if you want to add $10 and $20 bills, etc. later or to adapt to other currencies that uses different coin values).
(Of course the array of units needs to be sorted in descending order).
10-18-2015 02:23 PM
@patomated wrote:
Here's my code.
As I said, you should try to make the code more scalable. Avoid all these duplicate operations and use arrays as much as possible.
You had way too many cases. For example the change code works perfectly well if the change is zero, so there is no need to add yet another case, adding more layers and artifically complicating the code. You can also change the output tunnels to "use default if unwired". Now you can eliminate all these extra diagram constants.
Also, since you currently don't allow pennies, the input should be coerced to multiples of 5 cents.
You need to secure the inputs. Currently, people could insert nothing, select a negative number of items, and get lots of change for free!
Here's a quick rewrite to give you some ideas. (I don't like the popup, so I took that out. The LED seems sufficient. Vending machines don't have popups).
Modify as needed.
10-18-2015 03:00 PM
I cannot thank you enough for all the help you provide!
I had not realized that it works just the same if amount inserted equals the price
selecting a negative number also leads to getting free change
thanks for the simple code 🙂 much appreciated