Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #include <map>
- #include <iomanip>
- using namespace std;
- int main() {
- void operationsBetweenNumbers(); operationsBetweenNumbers();
- return 0;
- }
- void operationsBetweenNumbers(){
- int a; int b; cin >> a >> b;
- string _operator; cin >> _operator;
- bool isZero = b == 0;
- string noZeroDiv = "Cannot divide " + to_string(a) + " by zero";
- string evenOdd[] = {"even","odd"};
- ostringstream div; div << fixed << setprecision(2) << a / (double)b;
- string division = isZero ? noZeroDiv : div.str();
- //Instances of del and deletion variable were renamed to div, division respectively. Due to closer sounding of del to abbreviation of "delenie" in Bulgarian, such a mistake had occured.
- map<string, string>operators = {{"+", to_string(a + b)}, {"-", to_string(a - b)}, {"*", to_string(a * b)}, {"/", division}, {"%", isZero ? noZeroDiv : to_string(a % b)} };
- if (operators[_operator] == noZeroDiv) {cout << noZeroDiv; return;}
- cout << a <<" "<< _operator <<" "<< b << " = " << operators[_operator];
- if (_operator == "+" || _operator == "-" || _operator == "*") cout << " - " << evenOdd[abs(stoi(operators[_operator])) % 2];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement