Nathan Coulas

Equation Solver

gfssoc2j3 CPP17 06 May, 2020 0.121s 5 points

Source Code

#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int total = 0;
	string inp = "";
	cin >> total;
	cin >> inp;
	while(inp != "="){
		if(inp == "P"){
			cin >> inp;
			if(inp == "=") break;
			total += stoi(inp);
		}else{
			cin >> inp;
			if(inp == "=") break;
			total -= stoi(inp);
		}
		cin >> inp;
	}
	cout << total << "\n";
	return 0;
}