Guest User

Untitled

a guest
Jun 12th, 2013
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. 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;}};
  5.  
  6. int main()
  7. {
  8.     int act=-1;
  9.     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;
  10.     do
  11.     {
  12.         std::cout << "Enter action: " << std::endl;
  13.         std::cin >> act;
  14.     } while (act < 0 || act > 4);
  15.      
  16.     return (act == 0) ? 0 : [](int act){
  17.         double v1, v2;
  18.         std::cout << "and now for some values: ";
  19.         std::cin >> v1 >> v2;
  20.         std::cout << ops[act - 1](v1, v2) << std::endl;
  21.         return 0;
  22.     }(act);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment