Sorry for my lack of English skills.
I want to do an arithmetic operation specified in a string, e.g. "1 + 3 * 11 - 7 / 18".
Multiplication and division have higher priority than addition and subtraction. In the case of operations with the same priority, operations are performed in order from left to right.
I've written code that computes the addition. But I can not get to the next step.
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cout << "Enter an arithmetic operation EX) 1 + 3 * 11 + 7 / 18 " << endl;
getline(cin, s, '\n');
int sum = 0;
int search = 0;
while(true) {
int plus = s.find('+', search);
if(plus == -1) {
string aos = s.substr(search);
if(aos == "") break;
cout << aos << endl;
sum += stoi(aos);
break;
}
int count = plus - search;
string aos = s.substr(search, count);
cout << aos << endl;
sum += stoi(aos);
search = plus+1;
}
cout << "Result is " << sum;
}