aspose file tools*
The moose likes Beginning Java and the fly likes What am I doing wrong Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What am I doing wrong" Watch "What am I doing wrong" New topic
Author

What am I doing wrong

Chris Hathaway
Greenhorn

Joined: Feb 08, 2012
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
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

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

Joined: Feb 08, 2012
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

Joined: Feb 07, 2012
Posts: 3


maybe this is your need
Chris Hathaway
Greenhorn

Joined: Feb 08, 2012
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

Joined: Feb 07, 2012
Posts: 3
sorry .
first
.your code is not useful

dividing $47.63 is sharing $47.63

one man named tendollar get 4 so the money is Surplus $7.63
one man named fivedollar get 1 in $7.63 so the money is Surplus $2.63

````but what your method is the man named tendollar get 4 in $47.63 the man named fivedollar get 9 in $47.63 ```

hope could give you help
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: What am I doing wrong