Ok so ive already looked up solutions to my problem and my teacher does not allow me to use a simple iterator for the delete instead this is a hard coded delete function. what this program does is ask the user for 10 numbers and creates a vector of size 10 it then sorts the numbers in ascending order. then my program asks the user what integer he/she would like to delete in the program. and if there are multiple instances of this number it deletes those as well. My finderase function uses a loop to go through and make comparisions using the erase function it works in some instances but heres were it gets weird it wont work if the number im looking to delete is the last number in the vector. im assuming its maybe my index is off by a few numbers under my finderase() function or something ive been working hard to find a solution any help would be appreciated

``````void erase(vector <int>& v,int pos) {
for (unsigned int c=pos; c < v.size() - 1; c++){
v[c] = v[c+1];
cout << v[c+1] << endl;
//cout << " v[" << c << "]= " << v[c] << endl;
}
v.pop_back();
}
//Function used to enter the integer and pass it to erase.
void finderase(vector<int>&v,int &num)
{
for(int i=0;i < v.size();i++){
while (num==v[i]){
erase(v,i);
}
}
}
int main()
{
//Size of the vector
//Variable for user to choose number to delete.
vector <int> betsy;
//Counter used for filling the vector and displaying it.
int z=0;
//Integer to store delete.
int del;
int userinput=0;
//Vector entry
for (int i=0; i < 10; i++){
cout << "Enter an integer into the vector";
cin >> userinput;
betsy.push_back(userinput);
}
cout << "Enter an integer to delete.";
cin >> del;
finderase(betsy,del);
//Prints the vector after the delete.
cout << "myvector contains:";
for (z=0; z < betsy.size(); z++){
cout << " " << betsy.at(z);
cout << endl;
}
return 0;
}``````

Use code tags.

AFAIK the problem is in your finderase function.
Let's assume that your vector looks like this:
v[0]=5;
v[1]=5;
v[2]=6;
v[3]=6;
so the vector size is 4. Now, you want to delete value 6.
Your finderase function looks like this:

``````void finderase(vector<int>&v,int &num)
{
for(int i=0;i < v.size();i++){
while (num==v[i]){
erase(v,i);
}
}
}``````

For first two iterations nothing happens. On the third one we have:
vector size:4; i=2; we remove 6 (v[2]) from vector.
After that we attempt to do 4th iteration:
vector size:3 (changed!); i=3. Since the for loop condition is (i < v.size()) the 4th iteraton is not executed.

So that's my hint, and You should be able to solve the problem now.