English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

If I have a cost I need to apply to every 50,000 items I sell and a customer buys 75,000 items.

I find the number of times I need to apply the cost by rounding 75,000 up to 100,000 (the uppermost multiple of 50,000) and diving by 50,000 (= 2 times).

Any ideas?

2006-08-16 22:45:09 · 5 answers · asked by ? 2 in Computers & Internet Programming & Design

Thanks Leon but I don't it's as complicated as I first thought.
e.g
int GetCostMultiplier(int costThreshold, int qtySold)
{
int costMultiplier = 1;

while (costThreshold < qtySold)
{
costThreshold = costThreshold + costThreshold;
i++; // same as: i = i + 1
}

return costMultiplier;


}

seems to work.

2006-08-16 23:44:36 · update #1

I mean:
costMultiplier++; // same as: costMultiplier = costMultiplier + costMultiplier

not i++;

(I renamed my variables for clarity)

2006-08-16 23:50:42 · update #2

5 answers

Hi.

You have a cost C
You have the number of items sold Ns
You have the volumes which you sell at V4S
C(i) = Cost as a function of item i
Ns(i) = Number of items sold of item i
V4S(i) = Volume of items of i that you sell.

The pseudo code is as follows:
For each item in an order, we'll refer to a item X, do the following:
if Ns(X) is less than V4S(X), set C(X) equal to V4S(X)
if Ns(X) is greater than V4S(X), set C(X) equal to twice V4S(X)

To implement this in Java, C/C++, PHP, or JavaScript, I recommend the following:

1. Create an associative array to map your cost of each item to a price. For example, in PHP:

$costs = array("item A" => 10.50, "item B" => 1.99);

2. Create an associative array to map your items to a volume

$volumes = array("item A" => 50000, "item B" => 25000);

3. Write the programming language specific statements to implement the pseudo code but using the arrays instead of the Ns(i), C(i), and V4S(i) references above. Fro example, in PHP:

function computeCost($itemName,$quantity)
{
if($cost[$itemName]) {
// Item exists in our cost array. If it didn't, the array
// would return Null i.e. false
if($quantity < $volumes[$itemName])
return $volumes[$itemName];
elseif ($quantity > $volumes[$itemName])
return ($volumes[$itemName] * 2);
else
return $volumes[$itemName];
} else {
return -1; // Return -1 will mean no match found in
// our cost array
}
}

I hope this helps.

-Leon S

2006-08-16 23:18:27 · answer #1 · answered by Leon Spencer 4 · 0 0

x=CEILING(items/50000)

x is an integer
Ceiling is a function that rounds up. This is language independent function. You will have to check the individual language functions.

2006-08-17 06:10:56 · answer #2 · answered by AnalProgrammer 7 · 0 0

x=cost of 50,000
y=total cost
x+1/2x=y

damn laptop took me about a min. to find the + button

2006-08-17 05:52:18 · answer #3 · answered by me 2 · 0 0

You need 1+INT(x/50000), where x is the number sold.

2006-08-17 05:50:26 · answer #4 · answered by gvih2g2 5 · 0 0

?????????

2006-08-17 06:11:55 · answer #5 · answered by Bubbles 2 · 0 0

fedest.com, questions and answers