So you are actually going to have to manually determine all of the breakpoints for items under a order of 25. Then basically use a lookup table type scenario to determine what to order for qty's less than 25. AS pointed out previously this is very similar to the Knapsack problem.
Basically your code would look something like;
int qtyOrder;
int qtyRemain;
int qty25pack;
int qty10pack;
int qty5pack;
int qty1pack;
//Grab as many 25 packs as possible
qty25pack = (qtyOrder % 25);
qtyRemain -= qty25Pack * 25;
//Here use your lookup table to determine what to order
// for the qty's that are less than 25
You could use some kind of greedy algorithm to determine it on the fly. Which would be ideal if the prices are expected to change a lot.
That could look something like filling the package size with an exact match and then determining the closest match that is just over the qty remaining and see if it is cheaper.
So for example:
//find the perfect product amount price
While (qtyRemain != 0) {
perfectPrice += (qtyRemain % nextSmallestSize) * nextSmallestPackagePrice;
qtyRemain -= (qtyReamin % nextSmallestSize)
}
//Find the closest match over price
While ((qtyRemain % nextSmallestSize) != 0){
closePrice += (qtyRemain % nextSmallestSize) * nextSmallestPackagePrice;
qtyRemain -= (qtyRemain % nextSmallestSize)
}
//add the last price before we reached the perfect price size
closePrice += nextSmallestPackagePrice;
//determine lowest price
if closePrice < perfectPrice {
cost = closePrice;
}
else {
cost = PerfectPrice;
}
This code is no where near complete but should give you an idea. Code is also probably not the greatest either.
Edit
The second chunk of code would go after the first chunk in place of the lookup