0

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!

JRags
  • 13
  • 5
  • This did initially work, FYI - somewhere along the way I made a change and now it 'half' works. – JRags Sep 23 '14 at 22:54
  • why the modulo (%) 10 ? – AlexanderBrevig Sep 23 '14 at 23:01
  • @JRags which half works? And what specifically is broken? – genisage Sep 23 '14 at 23:08
  • I made a previous post which was pretty much dumping the code according to Steve... so I shortened it as much as I could. – JRags Sep 23 '14 at 23:11
  • modulo - i need to go thru each digit and count how many times each digit 0-9 is repeated. my problem, what's 'half broken', is that even though it outputs the even/odd number that is used the most or the least properly, it doesn't output how many times that digit is repeated (excluding numbers that do not appear at all) – JRags Sep 23 '14 at 23:13

0 Answers0