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

Hi, I am in a MATLAB class, and I couldn\'t be able to write the code of this qu

ID: 3905011 • Letter: H

Question

Hi, I am in a MATLAB class, and I couldn't be able to write the code of this question. Can anyone please help me to write the script of this question as soon as possible?

2. “Roll” two dice. In this program, you will roll two dice until you roll a “7” or repeat the total of the first roll of the dice.

a. This program should use rand or randi to numbers to roll numbers from 1 to 6.

b. Try using randn to do the same.

c. I suggest using a “while loop.”

d. Output the result of the first roll, the number of rolls needed to repeat that roll or to roll a 7.

e. Output the sequence of rolls.

Explanation / Answer

dice = randi([1 6], 1, 2); start = dice(1) + dice(2); count = 0; while true dice = randi([1 6], 1, 2); total = dice(1) + dice(2); count = count+1; if total == 7 || total == start break; end end fprintf('Total number of iterations is %d ', count)

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