I've been trying to Implement a mathematical algorithm of Numerical computing, which evaluates root of a certain equation given a certain Value of X .
Actually I want to know if there's some shortcut through which I can take the function like f(x)=(x+2) from user using console and a value of int variable 'var' and than simply use f(var) to evaluate value of f(var).
below is a program which uses #define f(x) function, but my question is that :
is there a way I can take the function itself from the console via user input rather than hard coding it in the source code??
#include<iostream>
#include<iomanip>
#include<math.h>
#include<stdlib.h>
#define f(x) x+2
using namespace std;
int main()
{
int var = 0;
cout << "Enter value of var : ";
cin >> var;
cout << "\n Value of f(x) = " << f(var) << endl << endl;
}