Ad
Code
Diff
  • #include <ostream>
    using namespace std;
    
    string calculator(int a, char op, int b) {
        stringstream s;
        switch (op) {
            case '+': {s<<a+b; return s.str();}
            case '-': {s<<a-b; return s.str();}
            case '*': {s<<a*b; return s.str();}
            case '/': {b != 0 ? s<<a/b : s<<"Invalid Input!"; return s.str();}
            case '%': {s<<a%b; return s.str();}
            default: return "Invalid Input!";
        }
    }
    
    • #include <ostream>
    • using namespace std;
    • string calculator(char op, int a, int b) {
    • string calculator(int a, char op, int b) {
    • stringstream s;
    • switch (op) {
    • case '+': {s<<a+b; return s.str();}
    • case '-': {s<<a-b; return s.str();}
    • case '*': {s<<a*b; return s.str();}
    • case '/': {b != 0 ? s<<a/b : s<<"Invalid Input!"; return s.str();}
    • case '%': {s<<a%b; return s.str();}
    • default: return "Invalid Input!";
    • }
    • }