I am struggling with my code for finding occurrences of a number in an array. If a user provides 1230476 and 10034850 as their two integers, it should show that for even digits, the largest occurrence is 0 and number of occurrences is 4, and the smallest number of occurrences is 2, 6, 8 with only 1 occurrence. I am not getting the proper result for the number of occurrences here is my output:
How many integers (to be worked on)? 2
Enter integer #1: 1230476
Enter integer #2: 10034850
Occurence of all existing digits --
Digit 0 : 4
Digit 1 : 2
Digit 2 : 1
Digit 3 : 2
Digit 4 : 2
Digit 5 : 1
Digit 6 : 1
Digit 7 : 1
Digit 8 : 1
Occurence of all existing EVEN digits --
Digit 0 : 4
Digit 2 : 1
Digit 4 : 2
Digit 6 : 1
Digit 8 : 1
The even digit(s) that has/have the largest occurrence -
0
And the number of occurrence(s) : 1
The even digit(s) that has/have the smallest occurance -
2
6
8
And the number of occurence(s) : 1
Occurence of all existing ODD digits --
Digit 1 : 2
Digit 3 : 2
Digit 5 : 1
Digit 7 : 1
The odd digit(s) that has/have the largest occurrence -
And the number of occurrence(s) : 1
The odd digit(s) that has/have the smallest occurrence -
5
7
And the number of occurrence(s) : 1
my code is:
cout << "\n The even digit(s) that has/have the largest occurrence -";
for (i = 0; i < 10; i += 2) {
mostOccuringEven = digitCount[i] % 10;
if (digitCount[i] != 0) {
if (mostOccuringEven > integersToWorkOn) {
cout << "\n " << i;
}
}
}
cout << "\n And the number of occurrence(s) : " << mostOccuringEven;
This is my first time posting, so apologies if I'm not doing this right... Appreciate any help here!