I am working on a program to calculate how many of each type of coin you will get back as change, but it seems that the "OR EQUAL TO" part of ">=" doesn't work but I’m not sure why. If anyone can tell me why this happens or how to fix it I would be very thankful.
PS. I apologize ahead of time for any spelling errors that there might be. I am also aware that this might not be the most efficient way of doing this, but its how I chose to do it.
You know how you can't write the exact value of 1/3 or 1/6 in decimal? Well, similar problems exist in other numbering systems. Floating point numbers are inherently incapable of exactly representing certain values, such as 0.2, 0.1, 0.05, or 0.01. Such numbers have infinitely long fractional parts. Since the computer only has finite memory, it can only do the next best thing, which is storing an approximation of the number.
The lesson here is: don't use floating point types to store monetary values. A simple alternative would be to store the number of pennies in an integer.