Sum function: Counting cookies Row array troopCookieSales contains the number of
ID: 3816672 • Letter: S
Question
Sum function: Counting cookies Row array troopCookieSales contains the number of boxes of cookies sold by each troop member. Assign totalSales with the sum of all elements in troopCookie Sales. Ex: If troopCookiesales= [40, 52, 12, 88, 65, 18, 15, 72], then totalSales is 362. Your Function function totalSales = Count Sales (troopCookiesales) % troopCookiesales: Boxes of cookies sold % Assign total Sales with the sum of all elements in troop Cookiesales total sales = 0 end Code to call your function Count Sales ([40, 52, 12, 88, 65, 18, 15, 72])Explanation / Answer
We use the matlab function sum( ) for the given function. Code is shown below. Please don't forget to rate the answer if it helped. Thank you very much.
--------------------------------------
function totalSales = countSales(troopCookieSales)
%troopCookSales : Boxes of cookies sold
%sum is function that adds all elements passed to it. We are assigning
% it to function's return value
totalSales = sum(troopCookieSales)
end
%calling our function
t = countSales([40, 52, 12, 88, 65, 18, 15, 72])
sample output
t = 362
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.