I'm new to c++ and I have this problem.
1) to read all the results of throw from a file called "YahtzeIn.txt" which your program should expected to find in the directory you specified. The file will consist of each throw result in the following format:
2 2 4 4 2
4 1 3 2 1
3 4 4 5 2
1 2 2 6 1
4 4 3 3 4
1 2 1 2 2
1 2 2 2 2
5 2 5 1 6
6 6 2 1 4
1 1 1 1 4
6 6 6 3 5
3 4 2 6 2
3 6 4 3 6
4 4 1 2 5
3 3 3 3 3
5 5 5 5 5
1 4 1 5 4
1 4 5 3 6
2 2 4 1 6
6 6 2 2 2
1 6 5 1 5
1 3 3 2 3
2 2 2 2 2
6 4 4 4 4
3 2 4 3 6
5 2 1 5 6
6 4 6 4 4
2 1 6 3 5
4 4 1 4 4
5 5 5 5 5
2) you should create the file yourself and stored it into your working directory so you can use them to test your program. You can read and edit such file using the Dev-C editor or even Window's Notebook application, as the file are simply ASCII text readable file.
The program should be designed to accept results file with any numbers of throw within the range of 20 to 50. Having read in the file, your program should calculate the score of each throw of the 5 dices base on the formula and write the result into an output file named "YahtzeOut.txt" in the following format:
2 2 4 4 2 ==> 25
4 1 3 2 1 ==> 11
3 4 4 5 2 ==> 18
1 2 2 6 1 ==> 12
4 4 3 3 4 ==> 25
1 2 1 2 2 ==> 25
1 2 2 2 2 ==> 30
5 2 5 1 6 ==> 19
6 6 2 1 4 ==> 19
1 1 1 1 4 ==> 30
6 6 6 3 5 ==> 26
3 4 2 6 2 ==> 17
3 6 4 3 6 ==> 22
4 4 1 2 5 ==> 16
3 3 3 3 3 ==> 50
5 5 5 5 5 ==> 50
1 4 1 5 4 ==> 15
1 4 5 3 6 ==> 19
2 2 4 1 6 ==> 15
6 6 2 2 2 ==> 25
1 6 5 1 5 ==> 18
1 3 3 2 3 ==> 12
2 2 2 2 2 ==> 50
6 4 4 4 4 ==> 30
3 2 4 3 6 ==> 18
5 2 1 5 6 ==> 19
6 4 6 4 4 ==> 25
2 1 6 3 5 ==> 17
4 4 1 4 4 ==> 30
5 5 5 5 5 ==> 50
3)Next your program should display the following information to the screen which is the number of occurrences for each number (1 to 6) from the throw result:
Dice Frequency
1's 2's 3's 4's 5's 6's
24 33 20 30 22 21
I've stucked on second question and so on. This question uses function and 2 dimension array but I have used any codes that written in C++ textbooks, still can't do this question.. Please help me..
I've done the first question so far, this is my coding,
@kemort
It didn't shown any formula. Let me re-type the whole thing.
In a game of dice called Yahtze a player rolls 5 dice and then is given a score depending on the pattern of numbers on the tops of the dice. Each dice has six sides bearing the numbers 1 to 6. So the result of a throw of the 5 dice can be represented by 5 numbers in the range 1 to 6 and the 5 numbers can be stored in an array. So for example the THROW 2,6,3,6,2 can be stored like this:
0 1 2 3 4
THROW 3 4 1 1 3
A program is required to calculate the score from the THROW as follows:
-50 points for "all-the-same" (5 of a kind) e.g. 4,4,4,4,4
-30 points for "4-the-same" (4 of a kind) e.g. 3,4,3,3,3
-25 points for "3-the-same and 2-the-same" (3 of a kind and a pair) e.g. 5,1,5,5,1 otherwise the score is the sum of the numbers
It may be useful to compute another array of numbers being the count of the times each number occurs in THROW.
1's 2's 3's 4's 5's 6's
COUNT 2 0 2 1 0 0
*the rest continue from above.
I stucked on this part. I couldn't find any formula.
Yep, that's the sort of thing I was looking for. I can't help for a while but somebody else might come along in the meantime. What you have to do is analyse each row of numbers for the number of duplicates etc and apply a score. From part 1 you have been able to read each line into the array num. Once you know the score, it's easy to output in the format to the file.
Adding the results to the frequency count array is easier.
@kemort
but the point is .. how I gonna write it ? I know is easy to add the result into frequency count. All the files has to been in one file that can run and get the final result which is:
Dice Frequency
1's 2's 3's 4's 5's 6's
24 33 20 30 22 21
Actually if you do a frequency count on the individual coin toss series (of 5) then that is an easy way of counting duplicates etc and thus get the score. That same frequency count can then be accumulated to the global frequency count. That's not a huge amount of work when compared to the other methods I originally thought might.be involved.
e.g if there is a triple then one of the counts will be 3 ... so simple. :)
kenjilee, I'll see what I can do. But a person of your talents would have come up with code by now given that your successful earlier attempt for part 1. It wouldn't be fair to deprive you of your creative ability by doing it for you.