|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Summer Labview Challenge 2
The challenge is to create a change machine
Part 1 You have an item that cost X and you are given X amount of money. The program will need to give back the correct amount and least amount of dollars and coins Example: You have a basketball that cost $10.23 and they give you $20. You will need to give them back 1 five dollar bill, 4 one dollar bills, 3 quarts, 2 pennies Inputs: 1) Cost of Item 2) Amount Paid Outputs: 1) Number of $20 2) Number of $10 3) Number of $5 4) Number of $1 5) Number of Quarters 6) Number of Dimes 7) Number of Nickels 8) Number of Pennies Part 2: Same as above but you only have a limited number of each denomination however you still need to give the correct amount of change. If you cannot give back the correct amount you will need to give a fault and notify the clerk Example: You have a basketball that cost $10.23 and they give you $20. However you only have 2 quarters. You will need to give them back 1 five dollar bill, 4 one dollar bills, 2 quarts, 2 dimes, 1 nickel and 2 pennies Inputs: 1) Cost of Item 2) Amount Paid 3) Amount of $20 4) Amount of $10 5) Amount of $5 6) Amount of $1 7) Amount of Quarters 8) Amount of Dimes 9) Amount of Nickels 10) Amount of Pennies Outputs: 1) Number of $20 2) Number of $10 3) Number of $5 4) Number of $1 5) Number of Quarters 6) Number of Dimes 7) Number of Nickels 8) Number of Pennies 9) Cannot give back the correct change If you have any questions please feel free to ask them and post your result on here. Thanks |
|
#2
|
||||
|
||||
|
Re: Summer Labview Challenge 2
This is my solution to part 1... Im not so sure how to handle part 2.
http://postimg.org/image/nkqro4gxd/ |
|
#3
|
||||
|
||||
|
Re: Summer Labview Challenge 2
Quote:
Part 2 coming soon... Last edited by Ari423 : 07-21-2015 at 10:12 PM. |
|
#4
|
||||
|
||||
|
Re: Summer Labview Challenge 2
nice work. I look forward to seeing your answer to part 2
|
|
#5
|
|||
|
|||
|
Re: Summer Labview Challenge 2
Here is part 1.
I came across a strange LabVIEW bug while I was doing this. If you remove the "Workaround" code and put in the basketball example you will see it outputs only one penny. Part 2 coming soon. |
|
#6
|
||||
|
||||
|
Re: Summer Labview Challenge 2
This is my solution to both parts
Last edited by GuyM142 : 07-23-2015 at 06:02 PM. |
|
#7
|
||||
|
||||
|
Re: Summer Labview Challenge 2
Here is my submission to part II. It's similar to part I, except each time it adds how much of that type it's missing back into 'the pot'. At the end, I added a feature that calls the vi from part I to see what the minimum amount of extra change would be needed to make change correctly (the input wire is "paid" and "price" is left at the default of 0). I only had a brief chance to test the program, but I believe it works. If anyone finds a problem with it, please let me know.
|
|
#8
|
|||
|
|||
|
Re: Summer Labview Challenge 2
The strange bug happens because by the time you have made it to the penny calculation, the remainder is no longer a full two cents. If you display it with about 15 digits of precision, it is truly just a bit below, so the node returns almost a full penny as a remainder. This is largely due to the fact that floats cannot store base ten fractions precisely. The mixup rounds the value so that the small cumulative error resets. A different fixup would be to convert the initial value to units of pennies instead of dollars.
Greg McKaskle |
|
#9
|
|||
|
|||
|
Re: Summer Labview Challenge 2
Here's Part 2.
Quote:
|
|
#10
|
|||||
|
|||||
|
Re: Summer Labview Challenge 2
Quote:
Part of programming is understanding the underlying computer implementation, and this is just one of the quirks or limitations. |
|
#11
|
||||
|
||||
|
Re: Summer Labview Challenge 2
It is a limitation in the imementation of floating point numbers (like doubles or singles). If you convert the dollars to cents by multiplying by 100 and then cast that as an integer, the problem will go away because integers do not have that problem.
|
|
#12
|
|||||
|
|||||
|
Re: Summer Labview Challenge 2
Take a look at the Wikipedia article on floating point representation for a description of the issue we face:
https://en.wikipedia.org/wiki/Floating_point#Representable_numbers.2C_conversion _and_rounding Quote:
Last edited by Mark McLeod : 07-25-2015 at 10:13 AM. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|