Answer to Question #162298 in MatLAB for Hadia

Question #162298

Each week a builder makes an order of doors from a supplier. The doors normally cost $60 each, but the supplier gives a 10% discount for any order of 30 or more doors. The orders for the first 8 weeks of the year are given in the vector: orders = [20 40 15 30 25 45 10 35]

  1. (a) Write a MATLAB program using a for loop and if statement to find the total cost of the doors ordered.
  2. (b) Extend your program using the find command to find which weeks the builder obtained a discount. 
1
Expert's answer
2021-02-09T15:27:06-0500
% part a
orders = [20 40 15 30 25 45 10 35];
cost = 0;

for index = 1:8 % looping through each order

% 10% discount over 30 orders
if orders(index) >= 30
cost += orders(index)*60*0.9;
  
% normal price
else
cost += orders(index)*60;
end
end

% printig cost
cost

% part b
weeks = find(orders >= 30)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS