iterating over vector elments backwards

  2d-vector, c++, segmentation-fault

Hello I am pretty new to c++ and I am trying to implement a small program that iterates over a 2d vector backwards and adds the value of the vector to points.
If the points have already been added then I want to overwrite the value of the vector with 99.
So for example if number of climbs is four then add the of the program points should have the value 5 and the vector should look like this at the end

{1, 1 ,1},

{99, 1, 1},

{99(should start here), 99, 99} 

But I keep getting a segmentation fault and I don’t know whether I am iterating the vector backwards incorrectly.
Could someone help me out, is this even the right approach?
Thanks in advance.

This is my full code

#include <iostream>
#include <vector>
using namespace std;

int main()
{

    
    vector<vector<int>> vect
    {   {3}, //finish here
     
        {1, 1 ,1},
     
        {2, 1, 1},
     
        {1, 1, 1}  //start here
    };
    

  
  int points = 0;
    
  
    for (int i = 0; i < vect.size(); i++)
    {
        for (int j = 0; j < vect[i].size(); j++)
        {
            cout << vect[i][j] << " ";
        } 
        cout << endl;
    }
  
  int visited = 99;
  int number_of_climbs = 4;
  
  for(int i = 4; i >= 0; i--)
    
    for (int j = 0; j < number_of_climbs; j++)
        {
            if(vect[i][j] != 99)
            {
              points += vect[i][j];
              vect[i][j] = 99;;
              continue;
              
            }
        } 
    
  

    return 0;
}

Source: Windows Questions C++

LEAVE A COMMENT