# Displaying note/coin combinations from change

• 10-02-2012, 05:41 PM
Hazza
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.
• 10-02-2012, 05:50 PM
KevinWorkman
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?
• 10-02-2012, 05:58 PM
Hazza
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?
• 10-02-2012, 06:09 PM
Tolls
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.
• 10-02-2012, 07:39 PM
Keith Jackson
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.
• 10-02-2012, 09:23 PM
Hazza
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?!
• 10-02-2012, 09:33 PM
Keith Jackson
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.
• 10-02-2012, 11:51 PM
DarrylBurke
Re: Displaying note/coin combinations from change
Quote:

Originally Posted by Keith Jackson
I hope that while trying to stay vague, that I am not being too vague.

IMO that may be too precise.

db
• 10-03-2012, 12:34 AM
Hazza
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-03-2012, 12:52 AM
Keith Jackson
Re: Displaying note/coin combinations from change
Quote:

Originally Posted by DarrylBurke
IMO that may be too precise.

db

Sorry about that. I'll try better. ...... back to lurking......
• 10-03-2012, 01:09 AM
Hazza
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!