Here is the code
Code:
CArray temp, first, second;
for(contor = 0; contor < (int)simbols.size(); contor++)
{
if(simbols[contor] == '+')
{
for(i = 0; i < (int)arrays.size(); i++)
{
if(arrays[i].name == operations[contor])
{
first = arrays[i];
}
if(arrays[i].name == operations[contor + 1])
{
second = arrays[i];
}
}
temp += (first + second);
}
if(simbols[contor] == '-')
{
temp += (first - second);
}
}
Consider the following input line:
first + second - third
Ok. Arrays is a vector of type CArray, which contains the name of the array and a vector of type int, for the components. Operations is a string vector containing first, second, third and any other array that might appear in the line. Simbols is a string vector that contains + and - in the order they appear in the input line. Temp is going to retain the result of those sumations or differences.
I am adding the arrays two by two ... but it acts like this: 1 + 2 + 3 should be 6... but it does 1+ 2, then 2 + 3, and then 1 + 2 + 2 + 3 , which is 8... So how could I properly adjust the loop to calculate what I want, please?..