[thelist] mod (%) help

Brian Cummiskey brian at hondaswap.com
Thu Jul 17 02:04:44 CDT 2008

Aaron Vegh wrote:
> if (wheelqty % 4 == 0) {
> 	$wheel_discount = givediscount(wheelqty);
> }
> else {
> 	$wheel_discount = 0;
> }

Thanks Aaron.   I thought of something similar to this too, however, it 
doesn't take into account the fact that 4 should still be discounted, 
but the remainder would not be.  The problem is that the remainder 
doesn't roll over.

ie, if wheelqty = 6
we have 2 left over from the mod, so by that logic, nothing would get 
discounted.   the end result from ordering 6 wheels against 1 kit is 
that the 4 get discounted, the other 2 at regular price.   I can easily 
find this with the mod.

Now, take an example of 10 wheels (and this will be the case for 
anything over 8 wheels).
4 get the discount
10%4 mod returns 2
that leaves me 2 full price...   but now i'm missing 4 wheels due to the 
mod counter 'wrapping'  [1,2,3,0,1,2 <--- this is our 2 returned]

i somehow need to track each mod loop iteration, and then add that as 
'4' to the returned mod figure.  so, 4 + 2 returned from the modulus = 6 
at regular price.

Further, once this is worked out, I need to wrap it in another iteration 
to test against kit quantity....

if 2 kits, 8 wheels get discount.
if they only ordered 7, the 2nd set of 3 wheels doesn't count as a kit, 
so only 4 wheels get the discount out of the 7 and 3 at regular price.
if 8 , all 8 get discounted
if 9, 8 discounted, 1 regular price.

and so on for X kits

It seems so simple, yet i can't put it in a logical statement.

More information about the thelist mailing list