home *** CD-ROM | disk | FTP | other *** search
- /*********
- *
- * EOQ.C
- *
- * by Ralph Davis
- * modified by Tom Rettig
- *
- * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
- *
- *********/
-
- /* EOQ: Economic Order Quantity
-
- Computes economic quantity of inventory item to order.
-
- SYNTAX: EOQ(balance, demand, cost, price, overhead)
-
- where balance = amount on hand
- demand = average demand per order period
- cost = cost of placing an order
- price = unit purchase price
- overhead = percentage cost of purchase price
- for inventory overhead
-
- RETURNS: 0 if balance >= 2 * demand,
- otherwise amount to order as a long integer
- */
-
- #include "trlib.h"
-
- TRTYPE eoq()
- {
- if ( PCOUNT==5 && ISNUM(1) && ISNUM(2) &&
- ISNUM(3) && ISNUM(4) && ISNUM(5) )
- {
- double balance = _parnd(1);
- double demand = _parnd(2);
- double ordercost = _parnd(3);
- double purchase = _parnd(4);
- double overhead = _parnd(5);
-
- if (balance < (2.0 * demand))
- _retnl((long)(_tr_sqrt((2.0 * demand * ordercost)
- / (purchase * overhead))));
- else
- _retnl( (long)ERROR );
- }
- else
- _retnl( (long)ERROR );
- }
-