Submit your work to the dropbox for your section in a file named compsc.m Your a
ID: 2086815 • Letter: S
Question
Submit your work to the dropbox for your section in a file named compsc.m Your answer must be completely correct to demonstrate this Competency The cost of sending letters and packages items through the US Postal Service increased on January 21, 2018. For a letter weighing not more than 3.5 oz., the new rates are shown in the following table Weight not Over Oz Cost 0.50 0.71 0.92 1.13 2 3.5 Craft a User-Defined Function (UDF) that: accepts a value for the weight in ounces (oz.) as the first variable in the input argument list. displays the cost of mailing a letter of that weight to the CW is an easily understood format returns as the first argument in the output argument list the cost of mailing a letter of that weight displays an easily understood error message to the CW if the weight is greater than 3.5 oz. or a negative value for the weight has been entered Note 1: No data should be "echoed" to the CWExplanation / Answer
CODE:
function cost=weight_cost()
format short
wt=input('enter the weight of the mail in oz: ');
if wt>3.5
display('Weight cannot be over 3.5');
else
if wt<0
display('Weight cannot be negative');
end
end
if wt>0 && wt<=1
fprintf('cost of mailing the letter of weight %d is $0.50',wt);
cost=0.50;
else
if wt>1 && wt<=2
fprintf('cost of mailing the letter of weight %f is $0.71',wt);
cost=0.71;
else
if wt>2 && wt<=3
fprintf('cost of mailing the letter of weight %d is $0.92',wt);
cost=0.92;
else
if wt>3 && wt<=3.5
fprintf('cost of mailing the letter of weight %d is $1.13',wt);
cost=1.13;
end
end
end
end
OUTPUT:
>> weight_cost
enter the weight of the mail in oz: 1.2
cost of mailing the letter of weight 1.200000 is $0.71
ans =
0.7100
>> weight_cost
enter the weight of the mail in oz: 0.2
cost of mailing the letter of weight 2.000000e-01 is $0.50
ans =
0.5000
>> weight_cost
enter the weight of the mail in oz: -0.2
Weight cannot be negative