v.resize(2); // now it contains `{{} {}}`.
for(unsigned i=0; (i < values.size()-1); i++) //for each input except the last (3 iterations)
//starting with {5,8} and {3,4}
v[i].resize(2); //resize one of the vectors already in v to 2
//now v contains {{0,0}, {}
v.push_back(calculate(values[i], values[i + 1])); //push back the calculations
//now v contains {{0,0}, {}, {2,4}}
for(............. (i < values.size()-1); i++)
//next the middle pair of inputs {3,4} and {4,4}
v[i].resize(2); //resize one of the vectors already in v to 2
//now v contains {{0,0}, {0,0}, {2,4}}
v.push_back(calculate(values[i], values[i + 1])); //push back the calculations
//now v contains {{0,0}, {0,0}, {2,4}, {-1,0}}
for(............. (i < values.size()-1); i++)
//finally the last pair of inputs {4,4} and {2,1}
v[i].resize(2); //resize the {2,4} to 2, but it was already two
//now v contains {{0,0}, {0,0}, {2,4}, {-1,0}}
v.push_back(calculate(values[i], values[i + 1])); //push back the calculations
//now v contains {{0,0}, {0,0}, {2,4}, {-1,0}, {2,3}}
for(............. (i < values.size()-1); ....) //done iterating
Do you have a debugger? It's really important to learn how to step through code like this, have someone show you, or find a tutorial. Stepping through this code in a debugger would have made it obvious what was going on to you.
Luckily, the code is REALLY easy to fix:
std::vector<std::vector<double> > v;
for(unsigned i=0; i<values.size()-1; i+=2) //NOTE: i+=2!!!
{
v.push_back(calculate(values[i], values[i + 1]));
}