Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## Making change

I need to figure out the math for this program.

I have 2 inputs, Amount Owed and Amount Paid. Then from that I get Total Change (Amount Paid - Amount Owed). So if I have 500 Amount Paid and 272 Amount Owed, then Total Change is 228.

Now from that I convert that into dollars, quarters, dimes, nickels, pennies. So 228 would be 2 dollars, 1 quarters, 0 dimes, 0 nickels, 3 pennies. 844 would be 8 dollars, 1 quarters, 1 dimes, 1 nickels, 4 pennies.

2. ## Re: Making change

do not always use changeQuarters

```                changeDimes = remainingChange / 10;
remainingChange = remainingChange - changeDimes * 10;

changeNickels = remainingChange / 5;
remainingChange = remainingChange - changeNickels * 5;

changePennies = remainingChange / 1;
remainingChange = remainingChange - changePennies * 1;```

3. ## Re: Making change

If you can take what luck999 has given you and expand that to fit your problem, then you will be in good shape. Remember to go from largest to smallest.

4. ## Re: Making change

Originally Posted by luck999
do not always use changeQuarters
Yeah, that works. Thanks.

I wonder if there's a way to do it with modulus %?