This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi, im trying to calculate the amount of each coin given in change and to have the least amount of coins returned. I have a formula going, however, it is only calculating the amount of each coin seperatly. Say there was 9.50 in change, it is returning me change = 9 dollars, 38 quarters, 95 dimes, 190 nickels, 950 pennies. While the answer i was looking for would be 9 dollars, 2 quarters, 0 dimes, 0 nickels, 0 pennies.
It looks as if every time a method runs, the change does not transfer over. Im stuck on how to fix this
What have you done so far to isolate the problem? Have you stepped through the code with the IDE's debugger? or if you don't have a good IDE, have you put in System.out.println() statements
in the code? Have you debugged one case yet?
A critical aside, not directly related to your problem, but I have to mention it: never use float or double for money. Ever. Use the integer number of pennies. Floating point numbers don't add up the way pennies do. The problems will be subtle and hard to find, but some accountant will find it and jump all over your, er, back.