Write a MATLAB script (craps.m) that plays the dice game Craps. The player begin
ID: 3745324 • Letter: W
Question
Write a MATLAB script (craps.m) that plays the dice game Craps. The player begins by throwing two standard 6-sided dice. If the sum of the dice is 7 or 11, the player wins. If the sum is 2, 3 or 12, the player loses. Otherwise, the sum becomes the player's point. The player continues to roll until either the point comes up again, in which case the player wins, or the player throws 7, in which case they lose. When playing the game, your program will show a visual representation of the two dice. Moreover, the only user input is pressing the key.Explanation / Answer
prompt = 'Enter User Input? '; n = input(prompt) c=1; if n == 7||11 fprintf('Won on first roll') elseif n == 2||3||12 fprintf('Lost on first roll') else wn = n; fprintf('Winning number is %d! keep rolling! ', wn) while n ~= wn||7 prompt = 'Enter User Input'; n = input(prompt) c = c + 1; end if n == wn fprintf('Player won with a %d having rolled %d times', n, c) else fprintf('Player lost with a %d having rolled %d times', n, c) end end
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.