0

Why wont my code run correctly

It won't ouput correctly https://code.sololearn.com/c9Dkb8fqStZe/?ref=app

3rd Jun 2020, 3:29 AM
Jose
Jose - avatar
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)
3rd Jun 2020, 5:01 AM
JME
+ 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
3rd Jun 2020, 5:04 AM
JME
+ 1
Convert.ToInt32() rounds to the nearest int, hence the "rounding errors". Try Math.Floor() it rounds down. https://www.dotnetperls.com/math-floor
3rd Jun 2020, 3:35 PM
ODLNT
ODLNT - avatar
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?
3rd Jun 2020, 9:52 AM
Jose
Jose - avatar