im stuck pls help

get the size of an array and the numbers in it and if a number repeats dont print it.
ex:size 5, 13146
output: 1346
i want to know a possible continuation for this problem.

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>
using namespace std;
int main()
{
    int tam,contadorB=0;
    cin>>tam;
    int arregloA[tam],arregloB[tam],fantasma[tam],contador=0;
for(int i=0;i<tam;i++){
 cout<<"dame un numero"<<endl;
    cin>>arregloA[i];
}
for(int i=0;i<tam;i++){
 arregloA[i]=fantasma[i];   
}
    
for(int i=0;i<tam;i++){
       
     for(int j=0;j<tam;j++){
      if(arregloA[i]==fantasma[j]){
         contador=contador+1;
      }
          if(contador>=2){
          arregloB[contadorB]=arregloA[i];
          }
         
           contadorB++;
         }
   }
}
return 0;


thanks
Last edited on
Line 7 is illegal C++. You can't use a non-const variable as the size when declaring an array.

If you want to create an array whose size isn't known at compile-time, you're going to need to dynamically allocate it.

Of course, with C++, you should be using a std::vector, or some other container, rather than a C-style array.
Topic archived. No new replies allowed.