Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Function Name: compareTips % Inputs (3): - (double) the subtotal of a meal % - (

ID: 3648104 • Letter: F

Question

Function Name: compareTips
% Inputs (3): - (double) the subtotal of a meal
% - (double) sales tax percentage
% - (double) tip percentage
% Outputs (3): - (double) the tip amount before tax
% - (double) the tip amount after tax
% - (double) the absolute difference between the two
%
% Function Description:
% Several TAs were having a discussion about whether its better to tip
% before tax or after, and what the actual difference in the amount paid
% is. To solve this problem, write a function called "compareTips" that
% takes in the subtotal of a meal, the sales tax percentage, and the
% percentage of the tip and computes the tip before sales tax is applied,
% after sales tax is applied, and the difference between the two. The
% price should be rounded up to the nearest hundredth.
%
% Notes:
% - Round only after all calculations have been complete, i.e. it should
% be your last step for tip values. Then subtract to find the
% difference between the two.
% - Percentages will be represented with whole numbers, i.e. 8% will be
% given as 8.
%
% Hints:
% - You may find the ceil() function useful.
% - There is not a function that can round to the nearest hundreth in
% MATLAB. Instead, think about what happens when you multiply a number
% by 100 and then round up, and go from there.
%
% Test Cases:
% [tipBefore tipAfter difference] = compareTips(23.45, 8, 15)
% tipBefore => 3.5200
% tipAfter => 3.8000
% difference => .2800
%
% [tipBefore tipAfter difference] = compareTips(101.68, 9.75, 20)
% tipBefore => 20.3400
% tipAfter => 22.3200
% difference => 1.9800

Explanation / Answer

%write to mfile and save as compareTips.m function [tBefore,tAfter,tAbs]=compareTips(subtotal,taxPCT,tipPCT) tBefore=subtotal*tipPCT/100; tAfter=(subtotal+(subtotal*taxPCT/100))*tipPCT/100; tAbs=abs(tBefore-tAfter); tBefore=ceil(tBefore*100)/100; tAfter=ceil(tAfter*100)/100; tAbs=round(tAbs*100)/100; %regular rounding %on side note, your other question, with cost of mpg, change 'round' to 'ceil'