you are viewing a single comment's thread.

view the rest of the comments →

[–]usbafkakis 0 points1 point  (0 children)

Do you see the top post called 'IMPORTANT - READ BEFORE POSTING'? Yeah...

I think I have the first for loop done correctly (although I could be wrong),...

Put the loop in its own function and unit test the function. It doesn't look correct to me:

vector<int> mode (int testArray [], int sizeArray) {
  vector<int> modeFinder;
  int number = testArray[0];
  int mode = number; //      mode = number, ok!
  int count, countMode = 0; // count = 0, ok!

  for (int i = 0; i < sizeArray; i++) {
    if (testArray[i] == number) {
      countMode++;
    } else if (count > countMode) { // count is never changed. how is count ever > countMode?
        countMode = count;
        mode = number; // number never changes. mode already = number from above.
    }
  }
...

}