I have a large array of numbers that range from 1-5. I need to get the total of each number in the array and and place it into another array, with the total of number of 1s in the first position of the array, total number of 2s in the second position, etc.
So if I had arr1[10] = {1,4,3,1,2,4,5,4,1,3}, I would want to get to arr2[5] = {3,1,2,3,1}.
However, with my current code, I get
1,0,0,1,0
Here is my code below:
n = 10
arr1[n] = {1,4,3,1,2,4,5,4,1,3}
arr2[5] = {0,0,0,0,0}
for (int i = 0; i < n; i++)
{
int rate = arr1[i];
if (arr2[i] == 0)
{
int count = 0;
if (rate == 1)
{
count += 1;
arr2[i] = count;
}
cout << count << endl;
}
}
arr2beyond its bounds)