1 Apple = £3.00 + (n x £1.00) * P
1 Date = £3.50 + (n x £1.20) * P
1 Chilli = £3.25 + (n x £1.10) * P
1 Mango = £2.50 + (n x £0.80) * P
Where n = the number you already have.
and P = your current amount / the maximum amount
If I have 5 Apples, and the maximum amount is 10
Cost of buying 1 apple =
= 3.00 + (5 * 1.00) * 5/10
= 8.00 * 0.5
= £4.00
Cost of buying 2 apples (6th and 7th)
=[ 3.00 + (5 * 1.00) * 5/10 ] + [ 3.00 + (6 * 1.00) * 6/10 ]
=(8.00 * 0.5) + (9.00 * 0.6)
=£9.40
Cost of buying all 5 apples (6th, 7th, 8th, 9th, 10th)
=(8 * 0.5) + (9 * 0.6) + (10 * 0.7) + (11 * 0.8) + (12 * 0.9)
=4.00 + 5.40 + 7.00 + 8.80 + 10.80
=£36.00
But how do I put that into a formula that will work for apples, dates, chillis and mangos When the values will be much larger.
Example
Cost of buying 999 apples when;
Current apples = 1500
Maximum apple = 2700
Cost of buying 899 mangos when;
Current mangos = 2601
Maximum mango = 3500
Edit:
If a minimum value is needed, P can't drop below 0.1
So.
If Current/Maximum < 0.1 : P = 0.1