My assignment is "...to fix the possible loss of accuracy when converting a double value to an int value. Enter the input as an integer whose last two digits represent the cents. For example, the input 1003 represents 10 dollars and 03 cents."

It's already solved for you above -- so just do what is done in the original program -- don't change the amount variable, but rather create and use a remainingAmount variable just like your example code uses. You'll also want to fix your nickel calculations to match the original program.

Also, I changed your quote tags to code tags so that your code doesn't lose its formatting. In the future you shouldn't use quote tags for code.

It's already solved for you above -- so just do what is done in the original program -- don't change the amount variable, but rather create and use a remainingAmount variable just like your example code uses. You'll also want to fix your nickel calculations to match the original program.

Also, I changed your quote tags to code tags so that your code doesn't lose its formatting. In the future you shouldn't use quote tags for code.

Good luck.

Thanks for the quick response!
Sorry for the QUOTE tag, I completely overlooked the # code. Its on about 12 am and i've been at this for 5 hours now. Little cock-eyed. And the 4 Guiness doesn't help.

It took me a while to understand what you meant, but i think i got it. Is this correct:

Which is what it should be! I mean is it correct as far as formatting? Never mind that doesn't make sense. I guess what I'm saying is i see what I did, but it hasn't hit me WHY I did it. Why did I have to define remainingAmount = amount. Maybe I'm just too tired to do the computations.

Also, i forgot to put the nickels i the orginal program. Eclipse was screaming at me and i ignored it.

Anyway, Thanks so much for the tip! I like when I can get a nudge, and not a full "here's the answer". It makes me think and learn what I need to do.

The key to understanding this is to understand what each line of code does. Take this line for instance:

Java Code:

amount = amount % 25;

The right hand side of this line, "amount % 25", means mod amount by 25, or in other words, divide amount by 25 and keep just remainder. So if amount is 85, amount divided by 25 is 3 with a remainder of 10, and that means that amount mod 25 (amount % 25) equals 10.

Now the key here is the left hand side of the code above:

Java Code:

amount = ....

which means take what ever's on the right hand side and set amount equal to that value. In other words, you are changing the value of amount -- and this is key. Eventually when you're done going through all the equations, if amount started out as 1003, it will end as 3, as you're finding out. The way to prevent this is to not change the value that amount holds, and the way to do this is to create a dummy variable, here remainingAmount, that is given the value held by amount, and then that gets changed instead. Make sense?

The right hand side of this line, "amount % 25", means mod amount by 25, or in other words, divide amount by 25 and keep just remainder. So if amount is 85, amount divided by 25 is 3 with a remainder of 10, and that means that amount mod 25 (amount % 25) equals 10.

This part I got. That was easy.

Originally Posted by Fubarable

Now the key here is the left hand side of the code above:

Java Code:

amount = ....

which means take what ever's on the right hand side and set amount equal to that value. In other words, you are changing the value of amount -- and this is key. Eventually when you're done going through all the equations, if amount started out as 1003, it will end as 3, as you're finding out. The way to prevent this is to not change the value that amount holds, and the way to do this is to create a dummy variable, here remainingAmount, that is given the value held by amount, and then that gets changed instead. Make sense?

Sukat, his eyes uncovered!. This makes sense. I am now seeing the code in a whole new light. Its so simple now that I know what to look for/at. Thanks again!