% Set parameters
prob_customer = 1/7;
num_weeks = 104;

% Initialize stock to zero
stock = 0;

% Variables to keep track of total sales, etc
total_cust = 0;
total_sold = 0;
total_lost = 0;
total_inventory = 0;

% Print labels for tables
if (quiet ~= 1)
  fprintf('Week Weekday Stock Customers Sold Lost\n');
end

for week=1:num_weeks,
  % New tank arrives on day 1
  stock = stock + 1;
  for weekday=1:7,
    sold = 0;
    lost = 0;
    
    % Do we have a customer today
    random_num = rand(1);
    if random_num < prob_customer,
      customers = 1;
    else
      customers = 0;
    end

    % If we have a customer, process sale
    if customers == 1
      % If we have stock, then sell one
      if stock > 0
	sold = sold+1;
	stock = stock-1;
      else
	% Otherwise, lose customer
	lost = lost+1;
      end
    end

    % Track statistics
    total_cust = total_cust + customers;
    total_sold = total_sold + sold;
    total_lost = total_lost + lost;
    total_inventory = total_inventory + stock;
    
    % Display today's info
    if (quiet ~= 1)
      disp([week weekday stock customers sold lost]);
    end
  end
end

if (quiet ~= 1)
  fprintf('Total over simulation:\n');
  fprintf('Customers : %i\n',total_cust);
  fprintf('Tanks Sold: %i\n',total_sold);
  fprintf('Lost Sales: %i\n',total_lost);
  fprintf('Total Inventory: %i\n',total_inventory);
end
