# Thread: Matlab code

1. ## Matlab code

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.

2. 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

3. Originally Posted by CaptainBlack
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

Thanks a lot, I will try it first. I'm not very good with programming, my friend kind of said to me it can be done easily, like the above question I had, he said because it is more about understanding the situation, not the code. He said if I can't do the code, that means I actually don't understand the situation.
I'm not sure, but I guess I'll try to learn. Thanks again.