Hello all!

I have to code a program that gives an answer to the question: Which quantity of a given item do I have to take on stock, if I want to cover the incoming orders with a probability of 95%? The average of items ordered per period should be a parameter.

Input-Parameter #1: Percentage

Input-Parameter #2: Average

Output-Parameter: Needed stock

This mathematical problem can be solved with the so-called “probability mass function of Possion distribution”. See http://en.wikibooks.org/wiki/Statistics:Distributions/Poisson

To keep it simple I took the following restaurant-example out of wikibooks.org.

The question here is: How many dishes do I have to prepare, if I want to cover 95% of the orders?

My first draft of a program is:

```
define data local
1 #average (f8) init <4>
1 #percentage (N1.5) init <0.95> /* has to be < 1
*
1 #-average (f8)
1 #needed_dishes (I4)
1 #sum_probability (f8) (EM=9.9(10))
1 #factorial (F8)
end-define
*
#-average := #average * -1
#needed_dishes := -1
*
repeat
add 1 to #needed_dishes
if #needed_dishes = 0 /* 0! = 1
#factorial := 1
else
#factorial := #factorial * #needed_dishes
end-if
*
#sum_probability := #sum_probability + #average ** #needed_dishes /
#factorial * EXP(#-average)
*
display #needed_dishes #sum_probability #factorial
until #sum_probability >= #percentage
end-repeat
*
write 'Needed dishes:' #needed_dishes
*
end
```

Now the problem is:

The program works good for a very small average number of dishes (an average of 4 dishes and 95% --> 8 dishes). But let’s say I have a very very big restaurant and an average of 500 dishes per day. Then the factorial in the formula becomes very big and an NAT1301 occurs.

Any ideas how to solve the problem?

Thanks,

matthias