0
Why wont my code run correctly
It won't ouput correctly https://code.sololearn.com/c9Dkb8fqStZe/?ref=app
4 Respuestas
+ 1
1. You're not looking for partial coins so dont use decimals, cast things as ints
int numberOfDimes = (int)((dollarAmount % .25m) / .10m)
+ 1
2. Your formula for calculating nickels and pennys is broken,
int numberOfNickels = (int)((dollarAmount % .35m) / .05m)
this doesnt really make sense if you think, test it with 10 cents which shouldn't have a remainder because it's exactly 1 dime, the formula would instead tell you 2 nickels.
Try to figure out the formula yourself if you need more help you can post here
+ 1
Convert.ToInt32() rounds to the nearest int, hence the "rounding errors".
Try Math.Floor() it rounds down.
https://www.dotnetperls.com/math-floor
0
I made some changes, but with int I believe I'm getting a rounding error with certain numbers. How do I make it more accurate?