Performs calculation with operators given in an unknown order Problem Statement

Write a simple interpreter which understands "+", "-", and "*" operations. Apply the operations with the correct order of operations (i.e. multiply, then add or subtract) using command/arg pairs starting with the initial value of value. The commands will not necessarily be given in the correct order of operations.

Arguments given: int value, vector&lt;char&gt; operations, vector&lt;int&gt; args

My Solution (C++)

int simpleInterpreter(int value, vector&lt;char&gt; operations, vector&lt;int&gt; args) {
    int index = 0;

    for (char operation : operations) {
        if (operation == '*') {
            value *= args[index];
        index++;
        }
    }

    for (char operation : operations) {
        if (operation == '+') {
            value += args[index];
        index++;
        } else if (operation == '-') {
            value -= args[index];
            index++;
        }
    }

    return value;
}


Example cases:  


simpleInterpreter(0, {'+', '+', '*'}, {5000000, 1, 2}) =&gt; 3
simpleInterpreter(1, {'*', '-', '*', '+'}, {-1, -1, 1, 1) =&gt; 1
simpleInterpreter(45, {'+', '*', '-'}, {2, 90, 180}) =&gt; 0
simpleInterpreter(100, {'+', '+', '*'}, {0, 5, 2}) =&gt; 7


I'm not really concerned about having safe input / I don't care about bad input. I'm mostly focused on readability and performance here.

Is this a good solution? What can be improved? Another solution I thought of would be to build a custom comparator and store the operations into a set of pairs (operator, how many times it appears), however this would increase space complexity without reducing time complexity so I didn't do that.
I find this task rather bizarre, but anyway…

The function signature should probably be

int simpleInterpreter(int value, const std::vector&lt;char&gt; &amp;operations, const std::vector&lt;int&gt; &amp;args)


Instead of writing separate index++; statements, I'd roll them into a post-increment operator:

value *= args[index++];


To be clear that index refers to the args vector, I'd rename index to argIndex.