This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 8B.1a)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_tableoneItemPrice = oneItem(1);oneItemNum = oneItem(2);costThisItemNoDiscount = oneItemPrice * oneItemNum;costThisItem = costThisItemNoDiscount * (1  discount);totalCost = totalCost + costThisItem;if totalCost > 50discount = 0.20;elseif totalCost > 20discount = 0.10;endendb)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....
View
Full
Document
This homework help was uploaded on 03/30/2008 for the course CSE 131 taught by Professor Sticklen during the Spring '08 term at Michigan State University.
 Spring '08
 Sticklen

Click to edit the document details