I am having an issue with my scoring method for a game called Yahtzee that I am writing for my school. I am using an array to store the final dice roll in but need to find a way to count how many of the ints in the array are of the same value. I know there is a way to do this with a vector using count but we have not learned this yet really and I would have to completely re-do my entire code.
Is there a way to do this? I can't seem to wrap my head around a method to use. Once I have a way to count how many like valued ints are in the array I can figure the rest out.
1 2 3 4 5 6 7 8 9
Ex:
die[5] = {1,1,1,3,4};
//I want to now count how many of each value there is then store it.
int ones = 3;
int twos = 0;
int threes = 1;
int four = 1;
int fives = 0;
int sixes = 0;
Something like this is what I am aiming for just don't know how to go about it.
int die[5] = {1,1,1,3,4};
int rolled[6] = {0,0,0,0,0,0};
// This line checks each dice for it's value
for (int i = 0; i < 5; i ++)
// This line takes the value of each dice, subtracts 1 from it (because it's an
// array), and increases that value's count
rolled[(die[i] - 1)] ++;