function [profit,cost,percent]=inventory(k,c,L,p,s,Q,x,h,l,time)
%initialize time, costs, number (demanded,short), time of next demand,order
t=0;  CH=0;  CS=0;  CO=0;  ND=0;  NS=0;  TD=exprnd(1/l,1,1);  TO=10^10;
%ET=(TD,TO);
while t<time
   if (TD<TO)           %execute if demand occurs before next order
      if (x>0)
         NS=NS+1;         % if stock>0, increment number of sales
      end
      [TD,TO,CH,t,x,CS,ND]=demand(TD,TO,CH,CS,ND,t,x,h,p,l,L,s);
      else              %if next order before next demand
          [CH,CO,TO,t,x]=order(TO,t,CH,x,h,Q,CO,k,c);
         end
end
cost=[CH,CS,CO];            % costs of holding inventory, shortage, and orders
percent=100*cost/sum(cost);  % percentage of cost in three categories
cost=sum(cost)/t;            % average costs per unit time
profit=1.5*(NS/t)-cost;      %return from sales - cost per unit time
