#include<iostream>

#include<string>

using namespace std;


int main()

{

string s;

cout << "문자 입력:" << endl;

getline(cin, s, '\n');

int sum = 0;

int startindex = 0;

while (true)

{

if (s.find('-') != string::npos) {

int findex = s.find('-', startindex);

if (findex == -1)

{

string part = s.substr(startindex);

if (part == "")

break;

cout << part << endl;

sum -= stoi(part);

break;

}

int count = findex - startindex;

string part = s.substr(startindex, count);

cout << part << endl;

sum += stoi(part);

startindex = findex + 1;

}

else if (s.find('+') != string::npos) {

int findex = s.find('+', startindex);

if (findex == -1)

{

string part = s.substr(startindex);

if (part == "")

break;

cout << part << endl;

sum += stoi(part);

break;

}

int count = findex - startindex;

string part = s.substr(startindex, count);

cout << part << endl;

sum += stoi(part);

startindex = findex + 1;

}

}

cout << "합은:" << sum << endl;

}


+와 - 문자를 인식해서 덧셈 뺄셈

즉 10+20-30-40+50 이런식으로 계산해주는 프로그램인데요

처음에 10+10이나 10-10은 잘먹히는데

그다음부턴(예를 들어서 10+10-30) 얘가 맛이 가버려요

뭐가 문제일까요?