• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with breaking change into bills and coins.  RSS feed

 
Alex Gallo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm tasked to code a program that scans items, totals their cost, then displays the change listed in separate bills and coins for the payment. I just can't figure out how to get it broken up into the bills and coins.





Any help would be greatly appreciated.
 
Vass Raptop
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alex.

The "%" operator might be really useful for you. It divides an integer by another and returns the remainder as value:

a,b,x,y are all integers (y<b)
If a = b*x +y then:
1) a/b=x (note that b*x does not equal a!!)
2) a%b=y

I'm sure you can find your own algorithm now. If you still struggle let me know.

Edit: A quick search after my post produced : http://www.coderanch.com/t/619901/java/java/Homework-int
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing you should do is turn off your computer. How would YOU "break change into bills and coins", using only your brain and maybe pencil and paper?

If you can't explain the process in words, you won't be able to convert it into code.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have added code tags, which you should always use, to your code, and you can see how much better it looks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!