[Solved] Using vectors in c++ [closed]


There are several things wrong with your program:

vector<int> pies[p], racks[p];

Should be:

vector<int> pies, racks;

The reason is that the first definition declares an array of vector. That certainly can’t be right, unless you really want to declare an array of vectors. What you want to do is declare two vectors that start out with no elements, and that is what the second line does.

You then have this:

 findthemaxpies( vector<int>& pies, vector<int>& racks);     

That line declares a function called findthemaspies. It is legal, but does nothing. If you want to call the function with those arguments, then it would be this:

 findthemaxpies( pies, racks);     

You have another issue with your second loop:

  for(j=0;j<p;j++)
  {
        cin>>p;                // reading the maximum weights of the racks
        racks.push_back(input);
  }

You are using p in the loop condition, but changing p in the loop, as well as using input that never changes value. That can’t be right. It probably should be something like this:

  int p2;
  for(int j=0; j<p; j++)
  {
     cin >> p2;                // reading the maximum weights of the racks
     racks.push_back(p2);
  }

solved Using vectors in c++ [closed]