Hello ialexsandu,
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
You have not included the header file <vector> nor have you defined a vector to use. What you have done is define a C style array of "int"s.
While discussing that area:
It is
ALWAYS a good practice and programming to initialize your variables. If your compiler is using the C++11 standards or after the easiest way to initialize variables is with empty {}s, e.g.,
int num{};
. This will initialize the variable to 0 (zero) or 0.0 for a double. A "char" will be initialized to "\0". "std::string"s are empty to start with and do not need to be initialized. Should you need to you can put a number between the {}s.You can also Initialize an array, e.g.,
int aNumbers[10]{};
. This will initialize all elements of the array to 0 (zero). A use of
int aNumbers[10]{ 1 };
will initial the first element to "1" and the rest of the array to "0".. Following the "1" with ", 2 ..." will initialize the array with the numbers that you have used up to the entire array.
Unless you have a use for "i" outside the for loop it is better to define "i" inside the for loop as:
for(int i = 0;i < n; ++i)
. And try to avoid using "<=" unless you are absolutely sure of what you are doing. Other wise you are likely to go past the end of the array or vector if you use them.
The array or vector along with others start at zero not one as C, C++ and other languages are zero based.
If you used a vector there is a function "vectorName.erase()" that will remove an element and adjust the vector's size for you. Using the C style array you will wither have to set an element to zero to deal with later or write all good elements to a new array. Otherwise you will have to keep track and change things dealing with the length of the array as you shorten things when you move things to the left.
Decide on which you would like to use the array or the vector? Or maybe you are calling the array by the wrong name.
Hope that helps,
Andy