### Problem with dynamic array

I want to calculate which modi are present in the numbers that the user gives in. This is the code:

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879`` ``````#include #include using namespace std; int main() { // Declaring variables // read in numbers int N; // how many numbers does the user want to give int * numbers; // array to save the numbers // statistics int * modus; // array to save modus int N_modus; // how many modus are there // help-variables int temporary; bool changed; int * unique_numbers; int * unique_numbers_freq; int N_unique_numbers; int frequency, max_freq; // as user how many numbers cout << "How many numbers do want to give in?" << endl; cin >> N; // make dynamic array numbers numbers = new int [N]; // ask user for numbers and save to array cout << "Give in the numbers."; for (int i=0; i>numbers[i]; // sort numbers from small to large do { changed = 0; for (int i = 0; i<(N-1); i++) { if (numbers[i+1]max_freq) max_freq = frequency; } //Put in the last number unique_numbers[N_unique_numbers] = numbers [N-1]; unique_numbers_freq[N_unique_numbers] = frequency; N_unique_numbers++;``````

However, the problem is, that when I want to show the array with the unique numbers with following code:

 ``123`` `````` // But here is the problem for (int i = 0; i < N_unique_numbers; i++) cout << unique_numbers[i] << " ";``````

I get this for output (when I give in 5 numbers: 1 2 3 4 5):
-842150451
-842150451
-842150451
4
5

Can anybody help me out?
Last edited on
Topic archived. No new replies allowed.