Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Homework 7 Iteration Function Name: scrabbleScore Inputs: 1. (double) A 1xN vect

ID: 3587674 • Letter: H

Question

Homework 7 Iteration Function Name: scrabbleScore Inputs: 1. (double) A 1xN vector of your word scores 2. (double) A 1xM vector of your opponents word scores Outputs: 1. (char) A string describing the outcome of the game Banned Functions: sum(), cumsum(), mean() Function Description: You and your friend just completed an intense game of scrabble. The scores were neck and neck, but now that the game has ended, you have to determine a winner. The worst part of any scrabble game is adding up the scores in the end, but with your newfound coding knowledge, you can use MATLAB to sum up the scores for you! Given two vectors of scores for each word played by you and your opponent throughout a scrabble game, write a function called scrabbleScore() that totals up your and your opponent's score and determines which player won. If your final score is greater, output: 'I am the Scrabble champion!' If however, your opponent's score was greater, output: "Beginner's luck. .. If the scores were equal, output: 'I challenge you to a rematch!

Explanation / Answer

function outtext = scrabbleScore(n,m)
% set initial sums to zero
nsum = 0;
msum = 0;
% calculate sum of vector n
for i=1:length(n)
nsum = nsum + n(i);
end
% calculate sum of vector m
for j=1:length(m)
msum = msum + m(j);
end
% compare nsum,msum and return output
if nsum>msum
outtext = "I am the Scrabble champion!"
else if(msum>nsum)
outtext = "Beginner's luck"
else
outtext = "I challenge you to a rematch!"
end
end

scrabbleScore([1 2 3 4],[1 2 3 4 5]);
scrabbleScore([1 2 3 4],[1 2 3 4]);
scrabbleScore([1 2 3 4],[1 2 3]);

% sample output
%outtext = Beginner's luck
%outtext = I challenge you to a rematch!
%outtext = I am the Scrabble champion!