Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <functional>
- std::function<double(double, double)> ops[] = {[](double x, double y){return x+y;}, [](double x, double y){return x-y;}, [](double x, double y){return x*y;}, [](double x, double y){return x/y;}};
- int main()
- {
- int act=-1;
- std::cout << "Hello. How much you smoked marijuana that the calculator talking to you?" << std::endl << "Actions:\n1 - addition\n2 - subtraction\n3 - multiplication\n4 - division\n0 - exit" << std::endl;
- do
- {
- std::cout << "Enter action: " << std::endl;
- std::cin >> act;
- } while (act < 0 || act > 4);
- return (act == 0) ? 0 : [](int act){
- double v1, v2;
- std::cout << "and now for some values: ";
- std::cin >> v1 >> v2;
- std::cout << ops[act - 1](v1, v2) << std::endl;
- return 0;
- }(act);
- }
Advertisement
Add Comment
Please, Sign In to add comment