Results 1 to 3 of 3

Math Help - Matlab code

  1. #1
    Member
    Joined
    Jul 2010
    Posts
    99

    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.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by tsang View Post
    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
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Member
    Joined
    Jul 2010
    Posts
    99
    Quote Originally Posted by CaptainBlack View Post
    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.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. MATLAB code
    Posted in the Calculus Forum
    Replies: 0
    Last Post: November 5th 2009, 06:44 AM
  2. matlab code helpppp :(
    Posted in the Math Software Forum
    Replies: 3
    Last Post: October 20th 2009, 01:06 AM
  3. matlab code sequences
    Posted in the Math Software Forum
    Replies: 1
    Last Post: October 20th 2009, 12:55 AM
  4. Need MAtlab code
    Posted in the Math Software Forum
    Replies: 1
    Last Post: April 26th 2009, 10:57 PM
  5. Need to do this by matlab code emengercy please help
    Posted in the Advanced Applied Math Forum
    Replies: 0
    Last Post: April 7th 2008, 07:30 PM

Search Tags


/mathhelpforum @mathhelpforum