-
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
-
What have you done so far?
-
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
-
Nothing helpful I'm affraid
-
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.
-
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.