1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
#include <map>
#include <functional>
double calculate(double first, double second, char op)
{
static const std::map<char, std::function<double(double, double)>> action = {
{'+', std::plus<double>()}, {'-', std::minus<double>()},
{'*', std::multiplies<double>()}, {'/', std::divides<double>()},
};
if(action.find(op) != action.end())
return action.at(op)(first, second);
else
return 0.0/0.0;
}
int main()
{
double first, second;
char op;
while(std::cin >> first >> op >> second)
std::cout << calculate(first, second, op) << '\n';
}
|