Help!!! not printing an array

My code is supposed make an array of 20 random numbers, print it, and then re-print the same array without any repeats. All repeats should be deleted. My code doesn't print the second array! Any suggestions??? Thanks!
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
#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<vector>

using namespace std;

int main(){

    srand(time(NULL));

    int ARRAY[20] = {};
    int sizeofarray = 20;
    int nubersArray[sizeofarray];

    for(int i = 0; i < sizeofarray; i++){
        nubersArray[i] = rand() % 20 + 1;
        cout << nubersArray[i] << " ";
    }
    cout << endl;

    for(int x = 0; x > nubersArray[x]; x++){
        if(ARRAY[nubersArray[x]] == 0){
           ARRAY[nubersArray[x]]++;
           cout << ARRAY[nubersArray[x]];
        }
    }
}
[code]
[/code]
Last edited on
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
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main() {
    srand(time(0));

    const int Size = 20;
    const int MaxNum = 10;

    int numbers[Size];
    bool used[MaxNum] = {};

    for (int i = 0; i < Size; ++i) {
        numbers[i] = rand() % MaxNum + 1;
        cout << numbers[i] << ' ';
    }
    cout << '\n';

    for (int i = 0; i < Size; ++i) {
        if (!used[numbers[i] - 1]) {
            used[numbers[i] - 1] = true;
            cout << numbers[i] << ' ';
        }
    }
    cout << '\n';
}

Last edited on
Thanks!
Topic archived. No new replies allowed.