Hello i have a problem with array counting instances of negative and numbers that go beyond array size. I made an array to count the number of instances of only numbers that are not beyond the size limit of 30. Been smashing my head for a few hours. Anything help is much appreciated!
Perhaps you should do it without the 'count' array. Just set int cnt=0, and then go through array 'arr' to count equal elements, increasing cnt by 1 on each iteration. WHen you find an element not equal to the previous element, print out cnt and reset it back to 0.
Also, it is better to use std::vector than c-style arrays.
Nah, your solution is still not good enough. And you have made it too complicated.
Try to figure out this one:
1 2 3 4 5 6 7 8 9
// extracting number of instances for each element in array
for( int i = 0; i < input; i++)
{
count++;
if(i==input-1 || arr[i] != arr[i+1]) {
cout << left << setw(10) << arr[i] << left << setw(10) << count << endl;
count =0;
}
}