#include <iostream>
#include <string>

using namespace std;

class DivideByZero {};
class UnknownOperator{};
class NegativeResult{};

class Calc {
    
public:
    int calculate( int a, char op, int b );
};

int Calc::calculate( int a, char op, int b )
{
    switch (op) {
        case '+':
            if( a + b < 0 ) throw NegativeResult();
            return a + b;
        case '-':
            if( a - b < 0 ) throw NegativeResult();
            return a - b;
        case '*':
            if( a - b < 0 ) throw NegativeResult();
            return a * b;
        case '/':
            if( b == 0 ) throw DivideByZero();
            if( a/b < 0 ) throw NegativeResult();
            return a/b;
        default:
            throw UnknownOperator();
    }
}

int main()
{
    Calc c;
    int a, b, result;
    char op;
    while(1) {
        cout << "\nPlease enter <val> <op> <val>" << endl << "> ";
        cin >> a >> op >> b;
        try {
            result = c.calculate( a, op, b );
            cout << "result is " << result << endl;
        } catch (DivideByZero e) {
            cout << "ERR: Divide By Zero" << endl;
        } catch (UnknownOperator e) {
            cout << "ERR: Unknown Operator" << endl;
        } catch (NegativeResult e) {
            cout << "ERR: Negative Result" << endl;
        }

    system("read");
    
}