This week's giveaway is in the Spring forum.We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!

# What am I doing wrong

Chris Hathaway
Greenhorn
Posts: 16
I apologize if this isnt the place to post questions in advance!

I have a program that im trying to build that takes a double value(such as 63.97) and tells you how much of each tender(10 dollar bills, 5, etc...) that it will take to match the original amount. When I go to run the program though, I get back how many of each bill it would take to hit the double value(such as 6 ten dollar bills, 6397 pennies, etc...), not sure if im explaining clearly, So far I have this

Now I think its either my Processing or my Output, any ideas or suggestions as to what might be the problem?

Paul Clapham
Sheriff
Posts: 20715
30
What you should do is to explain to yourself how to do the calculation with pencil and paper. Like this:

(1) I have \$63.97. So how many \$10 bills can I use? Well, I divide 6397 by 1000 and get 6.

(2) Okay, so now I have \$63.97. So how many \$5 bills can I use? Well, I divide 6397 by 5 and get 12.

... At this point you're going to stop me and explain what I did wrong. But that's what your code does. If you can fix my faulty calculation, then do the same fix to your code.

Chris Hathaway
Greenhorn
Posts: 16
Your right thats what my code does at the moment.

What I need it to do is to update the remaining balance

like say I use \$47.63, which was the teachers example, she got back

4 ten dollar bills
1 five dollar bills
2 one dollar bills
2 quarters
1 dimes
0 nickels
3 pennies

I dont think my code is updating the remaining balance, its still just dividing \$63.97, thus giving me values like 6397 pennies

George Black
Greenhorn
Posts: 3
• 1

Chris Hathaway
Greenhorn
Posts: 16
thank you very much it worked perfectly, but I was wondering if you could explain your thinking, just for notes and future reference!

George Black
Greenhorn
Posts: 3
sorry .
first