Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

What am I doing wrong

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 24635
56
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


maybe this is your need
 
Chris Hathaway
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!