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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Making change

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.
    Last edited by Jerick; October 7th, 2011 at 02:55 AM.


  2. #2
    Member
    Join Date
    Oct 2011
    Posts
    36
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Talking 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. #3

    Default 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.
    Kenneth Walter
    Software Developer
    http://kennywalter.com

  4. #4
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making change

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

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

Similar Threads

  1. So I'm making this program...
    By SkyAphid in forum The Cafe
    Replies: 2
    Last Post: August 29th, 2011, 05:55 PM
  2. Making Methods
    By kilroyjr in forum Java Theory & Questions
    Replies: 7
    Last Post: April 7th, 2011, 05:19 PM
  3. [SOLVED] Can't get boolean to change!!
    By Day2Day in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 2nd, 2010, 07:20 PM
  4. Change to JOptionPane
    By Liuric in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 1st, 2010, 12:07 AM
  5. Digital map application with Java GUI
    By donjuan in forum AWT / Java Swing
    Replies: 3
    Last Post: May 15th, 2009, 03:32 AM