View difference between Paste ID: aFpJqitN and yd5usWTs
SHOW: | | - or go back to the newest paste.
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-
    return (act == 0) ? 0 : [](int act){
16+
17-
    	double v1, v2;
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-
    	std::cout << "and now for some values: ";
18+