Guest User

Untitled

a guest
Jun 12th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     double v1, v2;
  10.     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;
  11.     do
  12.     {
  13.         std::cout << "Enter action: " << std::endl;
  14.         std::cin >> act;
  15.     } while (act < 0 || act > 4);
  16.      
  17.     return (act == 0) ? 0 : (std::cout << "and now for some values: ", std::cin >> v1 >> v2, std::cout << ops[act - 1](v1, v2) << std::endl, 0);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment