{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Unit11 Lab B - 8-B.1 a function totalCost =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
8-B.1 a) function totalCost = Prob8_B_1(costAndNum_table) % Compute the total cost of a grocery basket full of items % when the following sale terms apply: after $20, there is a % 10% discount; after $50, there is a 20% discount. Solve % using a LOOP. % INPUT: costAndNum_table, array, table in which each column % is ... <unitPrice; numItemsBought> % Note that the order is % significant; sale is % accomplished from low numbered % columns to high numbered % columns. % OUTPUT: totalCost, scalar, the total cost of the groceries. % sample call: % dataTable = [0.45,2.95,1.99,4.99,4.95,3.99,7.99,16.95,11.99; ... % 1, 1, 2, 1, 1, 2, 2, 1, 2]; % totCost = Prob8_B_1(dataTable) count = 1; totalCost = 0; discount = 0.0; for oneItem = costAndNum_table oneItemPrice = oneItem(1); oneItemNum = oneItem(2); costThisItemNoDiscount = oneItemPrice * oneItemNum; costThisItem = costThisItemNoDiscount * (1 - discount); totalCost = totalCost + costThisItem; if totalCost > 50 discount = 0.20; elseif totalCost > 20 discount = 0.10; end end b) function costAll = Prob8_B_1b(costAndNum_A) % Compute the total cost of a grocery basket full of items % when the following sale terms apply: after $20, there is a % 10% discount; after $50, there is a 20% discount. Solve % using vector operations. % INPUT: costAndNum_A, array, table in which each column % is ... <unitPrice; numItemsBought> % Note that the order is significant; % sale is accomplished from low % numbered columns to high numbered % columns.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}