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

Chapter 5: Loop Statements and Vectorizing Code Assume you are rolling two six -

ID: 3759791 • Letter: C

Question

Chapter 5: Loop Statements and Vectorizing Code Assume you are rolling two six - sided dice, each side having an equal chance of occurring. Write a function with header roll = mMonopolyDice() where roll is the sum of the values of the two dice thrown but with the following extra rule: if the two dice rolls are the same, then another roll is made, and the new sum added to the running total. If the two dice show 3 and 4, then the running total should be 7. 1f the two dice show 1 and 1, then the running total should be 2 plus the total of another throw. Rolls stop when the dice rolls are different. Hint: The line result = randi( [1 6],2,1) is an accurate simulation of rolling two dice Ceil(X) rounds the elements of X to the nearest integers towards infinity.

Explanation / Answer

function x = myMonopolyDice()
dice1 = randi([1 6], 2, 1);
dice2 = randi([1 6], 2, 1);
if dice1 == dice2
x = dice1 + dice2 + randi([1 6], 2, 1);
else
x = dice1 + dice2;
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote