The objective of this program is to remove duplicates from an array
Write a program that inputs an array of 10 integers from the user, and removes the duplicate array elements.
Here is some sample output: Please enter 10 integers, hitting return after each one: 5 75 10 75 5 80 10 5 5 50 You entered 5 unique numbers: 5 75 10 80 50
here is my code so far
#include <iostream>
using namespace std;
int main()
{
int myint[11];
int i,x,count=10;
cout << "Please input 10 integers, hitting return after each one \n";
for(i=0;i<10;i++){
cin>> myint[i];
}
for(i=0;i<=10;i++)
{
for(x=i+1;x<=10;x++)
{
if(myint[x]==myint[i])
{
count--;
for(i=x;i<=count;i++)
{ myint[i] = myint[i+1];
}
}
}
}
cout << endl;
cout << " You entered "<< count << " unique numbers: " << endl;
for(i=0;i<count;i++){
cout << myint[i] << " ";
}
return 0;
}
here is my output Please input 10 integers, hitting return after each one 5 75 10 75 5 80 10 5 5 50
You entered 7 unique numbers: 5 75 10 75 80 10 5
The duplicates have to be removed or written over and the unique numbers should be placed into a new array and not just displayed on the screen. Im not entirely sure where my error is. It seems somewhere the first time the loop runs it seems to be finding a duplicate no matter what and throwing the rest of the loops in the array off? Im kind of lost. Any help at all is appreciated. Thanks.