I am in Introduction to Programming and I don\'t know how to solve this problem.
ID: 3787300 • Letter: I
Question
I am in Introduction to Programming and I don't know how to solve this problem. Please explain legibly and step-by-step on how to code it. Thanks!
Write a function called income that takes two row vectors of the same length as input arguments.
The first vector, rate contains the number of various products a company manufactures per hour
simultaneously. The second vector, price includes the corresponding per item price they sell the
given product for. The function must return the overall income the company generates in a week
assuming a 6-day work week and two 8-hour long shifts per day.
Explanation / Answer
% matlab code
function sum = income(rate,price)
sum = 0;
if length(rate) != length(price)
disp("Both vectors should have same length");
quit
end
% start for loop
for i=1:length(rate)
sum = sum + rate(i)*price(i);
end
% end for loop
end
rate = [30 50 10 45 32 12 67];
price = [12.32 13.3 14 15 16.7 13.2 11.21];
fprintf("Total income: %0.2f ",income(rate,price));
% output: Total income: 3293.47
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.