Write a Yatzee Program

This is a discussion on Write a Yatzee Program within the C Programming forums, part of the General Programming Boards category; The odds of rolling a Yatzee on a single roll of 5 dice is 1/1296. Write a C program that ...

  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
    20,968
    What have you done so far?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,303
    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
    20,968
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 05:01 AM
  3. How to write a program for...
    By babyboy in forum C Programming
    Replies: 6
    Last Post: 02-15-2008, 05:17 AM
  4. Is there another way to write this program?
    By agentxx04 in forum C Programming
    Replies: 1
    Last Post: 11-23-2004, 08: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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21