function [AVE_DAILY_COST] = simulateprob7n5(num_runs, delivery_quantity) 

NUM_DAYS = 365
TRUCK_CAPACITY=4000;%tires
truck_charge = 400;%delivery cost per truck
delivery_charge = truck_charge*(floor((delivery_quantity-1)/TRUCK_CAPACITY)+1);
penalty = 10000;%10 dollar penalty per day * 1000 tires 

for i = 1:num_runs   
    i
    day_counter = 0;
    %Assume there is a delivery at the outset
    NUM_TIRES = delivery_quantity;%init 
    COST =delivery_charge;
    interest_rate = 0.01;
    days_without_tires =0;
    delivery_counter = 0;
    
    daily_inventory(1) = NUM_TIRES;

    while day_counter <= NUM_DAYS;
        %delivery subroutine
        %pick which manager is working
        u = rand(1);
        if u <.30;
            order_value = floor(.35*delivery_quantity);
        elseif u >=.30 & u < .80;
            order_value = floor(.20*delivery_quantity);
        else
            order_value = floor(.05*delivery_quantity);
        end   
            
        if NUM_TIRES < order_value
            NUM_TIRES = NUM_TIRES + delivery_quantity;
            COST = COST + delivery_charge;
            delivery_counter = 0;
        end
        
        NUM_TIRES = NUM_TIRES - flatdemand; %sell tires for day
       
        if NUM_TIRES <=0;%out of stock?
            days_without_tires = days_without_tires + 1;
            NUM_TIRES = 0;
        end    
        COST = COST + interest_rate*NUM_TIRES;%add charges for unsold tires
        day_counter = day_counter + 1;
        daily_inventory(day_counter+1) = NUM_TIRES;
        delivery_counter = delivery_counter + 1;
    end
    %add daily charge due interest at end of day for remaining tires
    cost_penalty = days_without_tires*penalty;
    AVE_DAILY_COST(i) = (COST + cost_penalty)/NUM_DAYS;
end
plot(daily_inventory)
xlabel('days in simulation')
ylabel('number of tires in stock')
plot(AVE_DAILY_COST)
days_without_tires 