Pseudocode:
Set money=-1 as an initial condition.
Create a while loop for when money~=0.
if money<0,
then money=input(‘How much money do you have?’).
else
fprintf(‘You now have $%.2f dollars.’,money)
end the conditional statement.
Set b=-1 as an initial condition.
Create a while loop for when b<0 or b>money
Set b=input(‘How much do you want to bet?’)
if b<0
then fprintf(‘Your bet must be at least zero.’)
end the conditional statement
if b>money
then fprintf(‘You cannot bet more than you have.’)
end the conditional statement
load the Dice file
set roll = randi([1 6],[1 2]) for a random dice roll
set S = roll (1) + roll (2) for the sum of the dice
fprintf(‘You rolled %i.’,S)
if S==7 or S==11
then imshow([Dice{roll}]) to open figure of dice roll
fprintf(‘You won %i dollars!’,b)
elseif S==2 or S==3 or S==12
then imshow([Dice{roll}]) to open figure of dice roll
fprintf(‘You lost %i dollars!’,b)
set b=b*(-1) to account for lost bet
else
imshow([Dice{roll}]) to open figure of dice roll
v=input(‘Press enter to roll again.’) to pause
set roll2 = randi([1 6],[1 2]) for a random dice roll
set k = roll2(1) + roll2(2)
Create a while loop for when k~=7 and k~=S
Set roll2 = randi([1 6],[1 2]) for random dice roll
imshow([Dice{roll2}]) to open figure of dice roll
fprintf(‘You rolled %i.’, k);
v=input(‘Press enter to roll again.’) to pause
set k = roll2(1) + roll2(2) for the sum of the dice
end
if k==7
then imshow([Dice{roll2}]) to open figure of dice
fprintf(‘You rolled 7.You lost %i dollars!’, b)
b=b*(-1) to account for lost bet
else
imshow([Dice{roll2}]) to open figure of dice roll
fprintf(‘You rolled your first roll. You won %i dollars!’, b)
end
end
money=money+b to account winnings or losses
end
fprintf(‘You lost all of your money!’)