c++ vector guestion

Write a program that inputs ten integer values from the keyboard. Each value should be pushed onto a
vector. After inputting the values, remove from the vector any repetition of a value. Finally output the list of
values that remain.
this is my homework but I dont understand exactly question can anybody explain to me how I can solve this question please
Here is the question again, make clearer.

Write a computer program.
The program will let the user enter ten numbers, using the keyboard.
You are to take each input value and store them in a vector
Then, look at that vector and remove any duplicate numbers.
Then, output each number from the vector to the screen.
#include <iostream>
#include<conio.h>
#include <vector>
using namespace std;
int main() {
int n;
cout<<"input ten numbers:"<<endl;
vector <int> v(n);
v[0]=1;
v[1]=2;
v[2]=3;
v[3]=4;
v[4]=5;
v[5]=6;
v[6]=7;
v[7]=8;
v[8]=9;
v[9]=10;
for(int i=0;i<v.size();i++)
cout<<v[i]<<" "<<endl;

for(int i=0;i<v.size();i++) {
if(v[i]%2==0) {
v.erase(v.begin()+i,v.begin()+i+1);
}
}
for(int i=0;i<v.size();i++) {
cout<<v[i]<<" "<<endl;
}
getch ();

}


I would like to remove duplicate numbers.I wrote this code but this is wrong cab anybody help me please what is the wrong

if(v[i]%2==0) {
v.erase(v.begin()+i,v.begin()+i+1);
}

This appears to be checking if a number is even, and then if it is, erasing lots of things from the vector. I have no idea why you're doing that.

Write a computer program.
The program will let the user enter ten numbers, using the keyboard.

Do that bit first.
First obvious problem:
1
2
3
nt n;
cout<<"input ten numbers:"<<endl;
vector <int> v(n);

What do you think is the value of n?
You should get 10 int from the keyboard not declaring them in code.
To remove duplicates you can sort the vector first and then use use std::unique
http://www.cplusplus.com/reference/algorithm/unique/
#include <iostream>
#include<conio.h>
#include <vector>
using namespace std;
int main() {
int n;
cout<<"input ten numbers:"<<endl;
cin>>n;

vector <int> v;
for(int i=0;i<v.size();i++)
cout<<v[i]<<" "<<endl;




getch ();
return 0;
}
Iam trying to solve this question but I couldnt please could anybody help me
#include <iostream>
#include<conio.h>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
int main() {
int n;
cout<<"input ten numbers:"<<endl;
vector <int> v(n);
v[0]=1;
v[1]=2;
v[2]=3;
v[3]=4;
v[4]=5;
v[5]=6;
v[6]=7;
v[7]=8;
v[8]=9;
v[9]=10;
for(int i=0;i<v.size();i++)
cout<<v[i]<<" "<<endl;

std::sort(v.begin(), v.end());
std::vector<int> result2;
for (int i = 0; i < v.size(); i++) {
if (i > 0 && v[i] == v[i - 1])
continue;
result2.push_back(v[i]);
getch ();

}
}
I wrote this but it is not true
Show us fetching one value from the keyboard.
I think I got this one and I even solved the problem I was having with;

1
2
3
vector<double>temps;
for(double temp; cin>>temp;)
temp.push_back(temp);


Try this;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int main()
{
      vector<int>V1;

      for (int x; V1.size() < 10; )
      {
            cin >> x;
            V1.push_back(x);
      }

      sort(V1.begin(), V1.end());

      for(int i = 0; i < V1.size(); ++i)
            if (i == 0 || V1[i - 1] != V1[i])
                  cout << V1[i] << " ";

      cin.get();
      return 0;
}


I put cin.get() instead of getch() simply because my Visual Studio 2017 doesn't recognize getch. I'm probably not using a header or something.

The first "for" statement will read the first ten integers and put it into the vector. So even if you put more than ten, it'll just take the first ten.

After sorting, the second "for" followed by "if" statements is what will check for repeating values. First it checks to see if it's the first integer in the vector and prints it, then it checks to see if each integer after is equal to the one before it and only print if it isn't.
Topic archived. No new replies allowed.