The cost per operating operating hour for rented construction machine is $10 per
ID: 2292203 • Letter: T
Question
The cost per operating operating hour for rented construction machine is $10 per hour for the first 10 hours, $8 per hour for each of the next 10 hours and $7 per hour in excess of 20 hours. Value for hours are 6 16 40. Don’t ask user to input these values. Write Matlab code using if, elseif, else to determine total cost. Use variable names rentalHours and totalCost The cost per operating operating hour for rented construction machine is $10 per hour for the first 10 hours, $8 per hour for each of the next 10 hours and $7 per hour in excess of 20 hours. Value for hours are 6 16 40. Don’t ask user to input these values. Write Matlab code using if, elseif, else to determine total cost. Use variable names rentalHours and totalCostExplanation / Answer
?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
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.