shippingCost - % error exit % else compute shipping weight...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
% shippingCost.m % (c) 2000 g.m. dick % the purpose of this program is to compute the shipping cost for a package % according to the following schedule: % - first 2 pounds . ................................. $10.00 % - each additional pound . .......................... $3.75 % - overweight charge of 70 pounds exceeded . ........ $10.00 % - the maximum shippable weight is 100 pounds % % data dictionary % parameters: % - baseRate - the base shipping rate for the first "baseWeight" pounds % - baseWeight - the base weight % - additional - rate for each additional pound (or part thereof) % - maxStandardWeight - maximum weight for standard rate % - overweight - the charge for exceeding "maxStandardWeight" % variables: % - weight - the package weight % - cost - the total shipping cost % % synopsis % read and validate weight % if weight invalid
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % error exit % else compute shipping weight % - standard charge % - overweight charge % print results % caution: a bug lurks here :-) clear % initialize parameters baseRate = 10; baseWeight = 2; maxStandardWeight = 70; additional = 3.75; overweight = 10; o % read and validate weight weight = input('Enter package weight(lb.): '); if isempty(weight) disp('you MUST enter a weight!') elseif weight > 100 disp(['weight of ', num2str(weight), ' exceeds 100 pounds - please see Federal Express.']) % compute shipping cost else % standard package cost = baseRate + ceil(weight-baseWeight)*additional; % overweight charge if (weight > maxStandardWeight) cost = cost + overweight; end end % print results disp(['total shipping cost for ', num2str(weight), ' pounds is $', num2str(cost)]);...
View Full Document

Ask a homework question - tutors are online