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

Write a script that will play a single game of what I call \"dumb Yahtzee\". In

ID: 3731109 • Letter: W

Question

Write a script that will play a single game of what I call "dumb Yahtzee". In this game, you will roll 5 dice on each turn. You will start with zero points. For your first turn, you add up the total of all dice that show a 1 and add this to your total score. For your second turn, you add the total of all dice that show a 2, You will take 6 turns. Print the final score to the command window at the end of the game. For instance, on turn 3, you roll: 14363 There are two 3's on this roll resulting in 2 x 3 = 6 points added to your total score. Hint - The MATLAB function randi (6,1) will simulate the rolling of one 6-sided dice. The function randi (6,1,5) will roll 5 of these dices. (I know, the plural is dice and the singular is die. But I don't want to confuse anyone here with my fancy East Coast grammar.)

Explanation / Answer

score=0;
for i=1:6 %no of turns
roll=randi(6,1,5);%simulate 5 dice
g=sprintf('%d ', roll);
fprintf('trail %d dice rolled as: %s ',i, g);
for j=1:5
if roll(j)==i%if equal then add to score
score=score+i;
end
end
end
fprintf("final score is %d",score);

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