% Nested selection statement example
%
% A shipping company calculates the shipping prices as follows:
% + A package weighing 5 lbs (pounds) or less costs $12, excluding tax.
% + A package weighing over 5 lbs and less than 10 lbs costs $18, excluding tax.
% + A package weighing at least 10 lbs costs $20 plus $1.50 for
%   each pound over 10 lbs. 
% For example, a 10.5 lb package costs $20.75 to ship, excluding tax. 
%
% Tax (8%) is charged for shipment to Region 1. No tax is charged for shipment to Region 2.
%
% Write a program that does the following:
% + prompts the user for the package weight (weight) and
%   destination code (code). The code must be entered as 1 or 2.
% + calculates the shipping charge (including tax) and stores the result in charge.
% + outputs the value of charge.
%
% Follow these additional specifications and assumptions:
% + Do not check for non-numerical inputs.
% + Assume that the user enters strictly valid weights and codes.
% + Do not output code or weight.

% Obtain shipping information:
  weight=input('Input the package weight: ');
  code=input('Input the destination code: ');
  pre_charge=0; % initial charge based on weight
  charge=0;     % final charge modified from pre_charge

% Determine the initial charge based on weight:
  if (weight<=5)
    pre_charge=12;
  elseif (weight<=10 & weight>5)
    pre_charge=18;
  else 
    pre_charge=20+(weight-10)*1.5;
  end

% Determinte the final charge by modifying the initial
% charge based on the code:
  if (code==1)
    tax=0.08;
  else
    tax=0;
  end
  
% Report the results:
  charge=pre_charge*(1+tax);
  disp(['Charge for the package: ',num2str(charge)]); 
