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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 8-B.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.

Page1 / 4

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online