?clc;
close all;
clear all;
Hours=[6 16 40];
totalCost=0;
for i=1:length(Hours)
rentalHours=Hours(i)
if rentalHours<10
totalCost=(rentalHours*10)
elseif rentalHours>10 && rentalHours<20
totalCost=totalCost+(10*10);
totalCost=totalCost+((rentalHours-10)*8)
elseif rentalHours>20
totalCost=totalCost+(10*10);
totalCost=totalCost+(10*8);
totalCost=totalCost+((rentalHours-20)*7)
end
end
?Results:
rentalHours = 6
totalCost = 60
rentalHours = 16
totalCost = 208
rentalHours = 40
totalCost = 528
Get Answers For Free
Most questions answered within 1 hours.