Hello,

Lets assume we have the amount 110,11 euro.

The used money bills are 500, 200, 100, 50, 20 10, 5, 2 , 1, 0.50, 0.20, 0.10, 0.05, 0.01.

So this amount would give on the console screen 1 x 100 1 x 10 1 x 0.10 1 x 0.01

How exactly can i split a random amount apart into its required bill / coins ? (without using a table/array)
Tried a switch with cases but it did not get me far.

Regards.

I suggest setting up an array of objects to represent your "used money bills" (and their counts). You can then execute a loop for each of those bills and calculate (a) how many of a given bill would be used and (b) what would be left after those bills were accounted for. Consider something like (pseudocode)

number of bills = amount / bill value, expressed as integer
amount left over = amount modulus bill value
next bill

Edit: On, you edited in "without using an array?" If that also precludes a collection, sounds like you're going to get some repetitive code, but you can still do it.

So i have 2 arrays (one for coinvalue and the other for coinamount)

``````double[] CoinVAlue = { 500, 200, 100, 50, 20, 10, 5, 2, 1, 0.5, 0.2, 0.05, 0.02, 0.01 };
uint[] CoinAmount = new uint[CoinValue.Length];``````

Then i have made a seperate class to split the amount .

``````public void SplitAmount(double Bedrag, uint MuntAantal, double MuntWaarde)
{
}``````

Although really no clue on how to split it exactly, do i need to call some index number of the array? Not sure how it exactly works to adress the proper numbers.

Or can this be done by linear // binair searching?

REgards.

Oh, so you can use an array. Go back to what I suggested, use a loop.

For each given bill (or coin) value in descending order, you want to know (a) how many times the value can be evenly divided into your amount and (b) how much of your amount would be remaining after those bills were accounted for.

That is literally the description of the loop and the contents thereof. Think about how would you code that.

I coded a small version of your program and plugged in an initial amount of 5352.18 and displayed the counts, output below.

``````500     10
200     1
100     1
50      1
20      0
10      0
5       0
2       1
1       0
0.5     0
0.2     0
0.1     1
0.05    1
0.01    3``````

The amount of code is minimal. See what you can come up with.

@apegram: The OP forgot to mention the value 0,02 in his first post. Although he mentioned it in his second post in his array definition.

@apegram: The OP forgot to mention the value 0,02 in his first post. Although he mentioned it in his second post in his array definition.

Well, that just ruins the whole thing!

``````500     10
200     1
100     1
50      1
20      0
10      0
5       0
2       1
1       0
0.5     0
0.2     0
0.1     1
0.05    1
0.02    1
0.01    1``````

I thought so, have you ever paid with coins that are as big as the nail of my pinky!