Reading data into vector & finding middle item HELP

Hello,

I am working on a code assignment that requires me to read data into a vector ( a website will input the data). Then, based on a vector's size, find the middle item. What I have so far code wise isn't much. here is what I have and I don't know if it is correct. If anyone can help with knowing what I have so far is correct and what the next step is to find the middle item once all integer have been inputed. Here you go and thank you in advanced.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <vector>
using namespace std;

int main()
{
int input;
int i;
vector<int> my_vec; //declare my vector
cin >> input;

//Printing out vector
for (int i = 0; i < input; i++)
{
         vec.push_back (i);
}


At Line 15 you're using a push_back this will have put your Input "i" at the back. I think you want to put "Input" with push_back to your vector.
Also you variable is wrong, you're writing vec.push_back it has to be "my_vec.push_back (i)".
If you want to read this vector, you need "pop_back" but keep in mind that will delete your value on the last place of vector!
I see. Thank you for catching my variable. I probably wont use the pushback action and instead use this code to fill my vector:
for (int i = 0; i < input; i++)
{
my_vec.at(input);
}
Topic archived. No new replies allowed.