Thread: Write a Yatzee Program

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    21

    Angry Write a Yatzee Program

    The odds of rolling a Yatzee on a single roll of 5 dice is 1/1296. Write a C program that tests this. Test it 1000 times.

    Ok so I tried to code it and found out I had no idea what to do. Tried few stuff didn't even came close. I'm new at this, its been a month I'm learning C. So it would be great is someone can help me. I dont want the whole code. A start, just give me scratch of a code, just to show me what to do. It will b a great help.

    **I don't want the whole game code, just the test part. The probabilities.
    **Algorithm that I kind of drafted
    1. Intro msg
    2. Ask the user if he wants to know the odds of rolling a Yatzee on a single roll of 5 dice.
    3. Test the program 1000 times and display the result.
    a. 5 dice randomly rolled
    b. Keep track of how many times a dice has been rolled.
    c. Keep rolling till it reached a Yatzee (mean time keep adding the rolls).
    d. After reaching a Yatzee start over and execute the program 1000 times. (mean time keep track of how many times it took to roll a Yatzee on each account).
    e. After running 1000 execution divide it by 1000 and the result should b close to the odd mentioned above.


    Thank You
    Last edited by newbi; 10-17-2012 at 11:02 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What have you done so far?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    The first thing you need to do is look up what the rules of Yatzee and be clear with what the assignment is asking you.

    When reading the rules and how it is played, you should start thinking of what algorithms you need -> Use a pen and paper and tell us what you come up with
    Fact - Beethoven wrote his first symphony in C

  4. #4
    Registered User
    Join Date
    Oct 2012
    Posts
    21
    Nothing helpful I'm affraid

  5. #5
    Registered User
    Join Date
    Oct 2012
    Posts
    21
    Well I don't need the rules. I just I have to test the probability. The algorithm that I came up with was:
    1. Intro msg
    2. Ask the user if he wants to know the odds of rolling a Yatzee on a single roll of 5 dice.
    3. Test the program 1000 times and display the result.
    a. 5 dice randomly rolled
    b. Keep track of how many times a dice has been rolled.
    c. Keep rolling till it reached a Yatzee (mean time keep adding the rolls).
    d. After reaching a Yatzee start over and execute the program 1000 times. (mean time keep track of how many times it took to roll a Yatzee on each account).
    e. After running 1000 execution divide it by 1000 and the result should b close to the odd mentioned above.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Well, if what you have done so far has not been helpful to you, then Click_here's suggestion is a place to start. If you find your assignment to be too difficult, simplify it first, i.e., to take it step by step. For example, maybe you could write a program that simulates a single die roll, then extend it to the rolling of five dice.

    EDIT:
    Hmm... your method of determining the probability is not what I expected (and I'm horrible at probability so I'm not sure if it is actually correct, after you fix it to sum the reciprocal of the number of rolls). It assumes that the probability is non-zero, otherwise you will keep rolling the dice forever. Now, the probability is indeed non-zero, but the method I expected is one where you roll the five dice say, 1296 times and record the number of times the "Yatzee condition" happens. Then, you repeat this process for a total of 1000 iterations.
    Last edited by laserlight; 10-17-2012 at 11:22 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Write program that uses MS-DOS?
    By Cgrasshopper in forum C Programming
    Replies: 5
    Last Post: 06-22-2010, 11:48 PM
  2. How to write a program for...
    By babyboy in forum C Programming
    Replies: 20
    Last Post: 02-19-2008, 06:01 AM
  3. How to write a program for...
    By babyboy in forum C Programming
    Replies: 6
    Last Post: 02-15-2008, 06:17 AM
  4. Is there another way to write this program?
    By agentxx04 in forum C Programming
    Replies: 1
    Last Post: 11-23-2004, 09:28 PM
  5. Help Write This Program Plz
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 10-13-2001, 01:08 AM

Tags for this Thread