Hi..

I am trying doing this exercise.Which is require a program that could ask the user how many integer he/she want to enter,and allow him/her entering them thus lastly display them all back.

i could just simply doing it by using an array,but this time i wanna use a vector to this,but it seems that my codes did not work.So i hope somebody could correct it for me..
This is what i have done :

int main() {

vector<double> data;

int count;
cout<<"How many numbers you want to enter? "<<endl;
cin>>count;
cout<<"Please enter values : "<<endl;
double input;

for(int i=0; i<count; i++)
{
  data.push_back(input);
    }

    cout<<endl;
for(int i=0; i<data.size(); i++)
{
  cout<<data[i]<<" ";
    }

system ("pause");
return 0;

and one more thing,could somebody explain more about differences using .push_back and cin>> in vector??

TQ :)

for(int i=0; i<count; i++)
{
    data.push_back(input);
}

This is your input loop, but there's no input going on. You need to give the user time to input a value, then add the value to your vector:

for (int i = 0; i < count; i++)
{
    if (cin>> input)
        data.push_back(input);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.