Mode

Hello. I have written some code to find the mode.

However I want it to output every mode.
Example

Input 2 2 3 3
Output 2 3

Here is what I have done
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  #include <iostream>
#include <algorithm>

using namespace std;

void calculateMode(int, int);

int main()
{
  
int size;

int aaa;

cout << "I will find the mode of a list of data. How big is your list?\n";

cin >> size;

int findMode[size] = {}; 

for(int n = 0; n < size; n++ )
{
  cin >> aaa;
  findMode[n] = aaa;
}

sort(findMode,findMode + size);

calculateMode(findMode,size);
  

}


void calculateMode(int array[], int big)
{
    
        int counter = 1;
        int max = 0;
        int mode = array[0];
        for (int pass = 0; pass < big - 1; pass++)
        {
           if ( array[pass] == array[pass+1] )
           {
              counter++;
              if ( counter > max )
              {
                  max = counter;
                  mode = array[pass];
              }
           } else
              counter = 1; // reset counter.
        }
    cout << "The mode is: " << mode << endl;
}


Any tips on formatting or syntax error. Thank you.
Last edited on
you've already been provided the solution to this once by lastchancel:
http://www.cplusplus.com/forum/beginner/210951/#msg989022
gunnerfunner

I am not very adept at c++. I was not sure how to implement it. I started over and used an array this time.

Topic archived. No new replies allowed.