Results 1 to 11 of 11
  1. #1
    Hazza is offline Member
    Join Date
    Oct 2012
    Posts
    64
    Rep Power
    0

    Default Displaying note/coin combinations from change

    I was just wondering how I could display note/coin combinations from a calculated amount?

    My program so far reads in a price for a certain shopping item and then works out the change due from the amount of cash a user enters. So say if 354 is read in as the value if the item, and then the user enters 400 on the keyboard, it displays the change as 46.00. What I want know is for it to also display the note/coin combinations to get this amount, so for this example it would be:

    10 pound notes - 4
    5 pound notes - 1
    2 pound coins - 0
    1 pound coins - 1
    50 pence coins - 0
    20 pence coins - 0
    10 pence coins - 0
    5 pence coins - 0
    2 pence coins - 0
    1 pence coins - 0

    How would I get the program to work this out?

    Any help would be greatly appreciated, thank you.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,965
    Rep Power
    8

    Default Re: Displaying note/coin combinations from change

    Isn't the whole point of the assignment for you to figure that out? What have you tried? Where are you stuck?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Hazza is offline Member
    Join Date
    Oct 2012
    Posts
    64
    Rep Power
    0

    Default Re: Displaying note/coin combinations from change

    I don't want people to write code for me! I was thinking about how I would work it out, and then apply this to a computer program. So, in my example, I would see that the change due is above the highest note available so I know it is going to need at least one of these and then check each one going down the list. I am just not too sure where to begin?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default Re: Displaying note/coin combinations from change

    The basic concept is, find how many of the highest value fit in your "change".
    Then take the remainder and do the same with the next highest.
    Repeat.

    There are likely several ways to achieve the above.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Keith Jackson is offline Member
    Join Date
    Sep 2012
    Location
    Maryland, USA
    Posts
    14
    Rep Power
    0

    Default Re: Displaying note/coin combinations from change

    To give you a general hint, I would convert the monetary amount to pence and use integer division and modulus.

  6. #6
    Hazza is offline Member
    Join Date
    Oct 2012
    Posts
    64
    Rep Power
    0

    Default Re: Displaying note/coin combinations from change

    I thought I had it but I keep getting an error saying "possible loss of precision" found:double required:int. But loss of precision is exactly what I want! Because you can't have 4.3 10 notes! Someone please help?!

  7. #7
    Keith Jackson is offline Member
    Join Date
    Sep 2012
    Location
    Maryland, USA
    Posts
    14
    Rep Power
    0

    Default Re: Displaying note/coin combinations from change

    If my British coinage conversion is correct ~ 46 pounds (I can't find the symbol) would be 4600 pence. You may need to cast this to an int in your code. Use integer division of 4600 / 1000 (the number of pence in a 10 pound note) and you should get 4. If you perform the same equation as a modulus ~ 4600 % 1000, you wind up with the 600 pence left over to convert. I hope that while trying to stay vague, that I am not being too vague.

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,254
    Rep Power
    19

    Default Re: Displaying note/coin combinations from change

    Quote Originally Posted by Keith Jackson View Post
    I hope that while trying to stay vague, that I am not being too vague.
    IMO that may be too precise.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    Hazza is offline Member
    Join Date
    Oct 2012
    Posts
    64
    Rep Power
    0

    Default Re: Displaying note/coin combinations from change

    Thank you everybody I have it now. The only problem I have now is that when the change is odd say 144.53 the program does not detect the final penny, so the change it displays adds up to 144.52?!?!

  10. #10
    Keith Jackson is offline Member
    Join Date
    Sep 2012
    Location
    Maryland, USA
    Posts
    14
    Rep Power
    0

    Default Re: Displaying note/coin combinations from change

    Quote Originally Posted by DarrylBurke View Post
    IMO that may be too precise.

    db
    Sorry about that. I'll try better. ...... back to lurking......

  11. #11
    Hazza is offline Member
    Join Date
    Oct 2012
    Posts
    64
    Rep Power
    0

    Default Re: Displaying note/coin combinations from change

    Actually my own program became better at maths than me! And it did add up to 144.53. So thank you for your help everybody :D!

Similar Threads

  1. arrange Combinations
    By silvathins in forum New To Java
    Replies: 0
    Last Post: 05-07-2012, 11:10 AM
  2. Combinations
    By atomant in forum New To Java
    Replies: 1
    Last Post: 02-22-2012, 07:41 AM
  3. Combinations in Java
    By Roam in forum New To Java
    Replies: 12
    Last Post: 08-25-2011, 10:22 PM
  4. Replies: 7
    Last Post: 05-05-2011, 10:45 AM
  5. Coin Change
    By Growler in forum New To Java
    Replies: 7
    Last Post: 09-23-2010, 05:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •