Originally Posted by
tsang Hi, I got a question here and I need to add some command to Matlab, but I really don't know the codes, can anyone please help me?
Here is the situation: The player throws two dice, and if the sum is seven or eleven, then she wins. If the sum is two, three or twelve, then she loses. If the sum is anything else, then she continues throwing until she either throws that number again (in which case she wins) or she throws a seven (in which case she loses).
Now, I need to add code for: the code such that player obtain a 7 or 11; the condition that we keep playing until the player either wins or loses; condition such that player wins; condition such that player loses.
Can anyone please teach me what should be the code for above parts? Thanks a lot.
Try something like (warning untested code):
Code:
flag=true;
win=false;
while flag
die=randint(1,2,[1,6]);
sumdie=sum(die);
if (sumdie==7)|(sumdie==11)
win=true;
flag=false;
end
if (sumdie==2)|(sumdie==3)|(sumdie==12)
win=false;
flag=false);
end
end