# Thread: Displaying note/coin combinations from change

1. Member
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.

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?

3. Member
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?

4. Moderator
Join Date
Apr 2009
Posts
13,541
Rep Power
27

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

5. Member
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.

6. Member
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?!

7. Member
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.

8. ## Re: Displaying note/coin combinations from change

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

9. Member
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?!?!

10. Member
Join Date
Sep 2012
Location
Maryland, USA
Posts
14
Rep Power
0

## Re: Displaying note/coin combinations from change

Originally Posted by DarrylBurke
IMO that may be too precise.

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

11. Member
Join Date
Oct 2012
Posts
64
Rep Power
0

## 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!

#### Posting Permissions

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