Array help please.

I am making a program where i remove duplicates from an array..

so far i have it so that the program recognizes the duplicates and shows them. It also tells me what array element it is "n"

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
31
32
33
34
35
36
#include "stdafx.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	int n=0, num, i=0, p, temp, ii=0;

	int max[10]={1, 4, 9, 10, 9, 7, 8, 7, 4, 3};

	for(i; i<10; i++){
		for(n=i+1; n<10; n++){
			if(max[i]==max[n]){
				cout<<"Array Element of Duplicate Number: "<<n<<" ";
				cout<<" "<<endl;
				cout<<" "<<endl;
				cout<<"Duplicate Number: "<<max[i]<<" ";
				cout<<" "<<endl;
				cout<<" "<<endl;
	
/*	for(n=0; n<10; n++){
		if(n=!i){
		cout<<max[n]<<" ";
	}*/
//	}
	}
	}
	}


	cout<<" "<<endl;
	cout<<" "<<endl;


	return 0;
}


my issue comes when i want to print the array without those array elements. So essentially my cout should display 7 numbers because it removed the duplicates.

any help would be good. I feel like i might be over complicating it a bit.
First of all it is a bad idea to name the array as max because this name can only confuse a reader of your code. What does max mean?!!!

The simplest way is to sort the array and then apply standard algorithm std::unique. For example,

1
2
3
4
5
6
7
8
9
10
11
12
const int N = 10;
int a[N] = { 1, 4, 9, 10, 9, 7, 8, 7, 4, 3 };

for ( int *p = a; p != a + N; ++p ) std::cout << *p << ' ';
std::cout << std::endl;

std::sort( std::begin( a ), std::end( a ) );

std::fill( std::unique( std::begin( a ), std::end( a ) ), std::end( a ), 0 );

for ( int *p = a; p != a + N; ++p ) std::cout << *p << ' ';
std::cout << std::endl << std::endl;


The other way is for example to copy the array into itself removing duplicates.
i could attempt and look into it, though I have yet to be lectured on these standard algorithms. Thanks for the input, I always appreciate it.
Topic archived. No new replies allowed.