Results 1 to 11 of 11
 10022012, 06:41 PM #1Member
 Join Date
 Oct 2012
 Posts
 64
 Rep Power
 0
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.
 10022012, 06:50 PM #2
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!
 10022012, 06:58 PM #3Member
 Join Date
 Oct 2012
 Posts
 64
 Rep Power
 0
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?
 10022012, 07:09 PM #4Moderator
 Join Date
 Apr 2009
 Posts
 12,224
 Rep Power
 20
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 **
 10022012, 08:39 PM #5Member
 Join Date
 Sep 2012
 Location
 Maryland, USA
 Posts
 14
 Rep Power
 0
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.
 10022012, 10:23 PM #6Member
 Join Date
 Oct 2012
 Posts
 64
 Rep Power
 0
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?!
 10022012, 10:33 PM #7Member
 Join Date
 Sep 2012
 Location
 Maryland, USA
 Posts
 14
 Rep Power
 0
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.
 10032012, 12:51 AM #8
 10032012, 01:34 AM #9Member
 Join Date
 Oct 2012
 Posts
 64
 Rep Power
 0
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?!?!
 10032012, 01:52 AM #10Member
 Join Date
 Sep 2012
 Location
 Maryland, USA
 Posts
 14
 Rep Power
 0
 10032012, 02:09 AM #11Member
 Join Date
 Oct 2012
 Posts
 64
 Rep Power
 0
Similar Threads

arrange Combinations
By silvathins in forum New To JavaReplies: 0Last Post: 05072012, 12:10 PM 
Combinations
By atomant in forum New To JavaReplies: 1Last Post: 02222012, 08:41 AM 
Combinations in Java
By Roam in forum New To JavaReplies: 12Last Post: 08252011, 11:22 PM 
how to capture keyboard strockes then change it then print into a note pad?
By Sank in forum New To JavaReplies: 7Last Post: 05052011, 11:45 AM 
Coin Change
By Growler in forum New To JavaReplies: 7Last Post: 09232010, 06:33 PM
Bookmarks