I'm having trouble determining what in my code is causing the message "Program.exe has stopped working." It displays the results properly, otherwise. Any suggestions?

#include <iostream>
using namespace std;

int main()
{
    const int numArraySize = 11;
    int numArray[] = {1, 2, 3, 3, 3, 2, 2, 1, 3, 4, 5};
    const int dupSize = 6;
    int dupArray[dupSize];
    int *frequency;
    int counter;
    int displacement;
    int mode = 0;

    for (counter=0; counter < numArraySize; counter++)
        {
            dupArray[counter] = 0;
            frequency = dupArray;
        }

    for (counter = 0; counter < numArraySize; counter++)
        {
            displacement = *(numArray+counter);
            (*(frequency+displacement))++;
        }

    int highest = *frequency;
    for (counter = 1; counter < dupSize; counter++)
        {
            if (*(frequency + counter) > highest)
            {
                highest = *(frequency + counter);
                mode =+ counter;
            }

        }

    if (highest > 1)
        cout << "The mode of the array is " << mode << "." << endl;
    else
        cout << "There is no mode." << endl;

    return 0;

I put that code on an online IDE and the code section starting at line 30 seems to be troublesome. I suggest you rewrite it to use your array and not make assumptions about the array being in contiguos memory and of a 6 byte size.

If it's only the mode you're interested in, have a look here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.