I wrote a function to take in a vector, a int position and a int value
void add(vector<int>& pro, int pos, int val){
pro[pos] += val;
while(pro[pos] > 9){
int carry = pro[pos]/10;
pro[pos] %= 10;
pos++;
pro[pos] += carry;
}//while
}//function add
lets say i have
vector<int> list1,list2,product;
list1.push_back(4);
list1.push_back(9);
list1.push_back(9);
list2.push_back(3);
list2.push_back(4);
vector<int>::reverse_iterator i,j;
int k,l;
for(j = list2.rbegin(), k = 0; j != list2.rend(); j++,k++){
for(i = list1.rbegin(), l = 0; i != list1.rend(); i++,l++){
add(product, k+l, (*j * *i) );
}//for i
}//for j
but its giving me an error after i execute it saying that "vector subscript out of range"
I'm not sure where this is coming from am I doing something wrong in my add function? Any help is appreciated. Thanks.