Thread: Calculation of a BOGOF deal - Should be easy

1. Calculation of a BOGOF deal - Should be easy

Hi,

I'm not sure if this is in the right place but I'm trying to develop logic for a promotions mechanic for some software. The example deal I'm working with is as follows:

Buy 2 cases - get 2 bottles free
Buy 3 cases - get 3 bottles free
Buy 10 cases - get 12 bottles free

I buy 5 cases - I get 5 bottles free (2,3)
I buy 7 cases - I get 7 bottles free (2,2,3)
I buy 13 cases - I get 15 bottles free (10,3)
etc....

The problem comes when I'm trying to program the logic on the 2 and 3 case deals. Because the ratio of free stock is the same, the calculations throw up all sorts of issues. Also, this is just one example....it could be a buy 5 get - 5 free / buy 12 get 15 free.... so in effect, a formula that can be used against any sort of promotion is needed.

I'd appreciate any help on this one, it's driving me mad!!

Thanks

Matt

2. Originally Posted by matthewwookie
Buy 2 cases - get 2 bottles free
Buy 3 cases - get 3 bottles free
Buy 10 cases - get 12 bottles free
Problem seems to be ONLY when number of cases ends with a 1; like 11, 21 ....
Like, with 10 or 11, you get 12 free, but with 12, you get 14 free; right?
So, after calculating the 10's, skip if remainder = 1; example:
51 cases: INT(51/10) = 5; free = 5 * 12 = 60; 51 - 5*10 = 1 : skip
53 cases: INT(51/10) = 5; free = 5 * 12 = 60; 53 - 5*10 = 3 : free = free + 3 = 60 + 3 = 63