#include <string> std::string calculator(int a, char op, int b) { switch (op) { case '+': return std::to_string(a+b); case '-': return std::to_string(a-b); case '*': return std::to_string(a*b); case '/': { return (b != 0 ? std::to_string(a/b) : "Invalid Input!"); } case '%': return std::to_string(a%b); default: return "Invalid Input!"; } }
#include <ostream>using namespace std;- #include <string>
string calculator(int a, char op, int b) {stringstream s;- std::string calculator(int a, char op, int b) {
- 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();}- case '+': return std::to_string(a+b);
- case '-': return std::to_string(a-b);
- case '*': return std::to_string(a*b);
- case '/': {
- return (b != 0 ? std::to_string(a/b) : "Invalid Input!");
- }
- case '%': return std::to_string(a%b);
- default: return "Invalid Input!";
- }
- }