the function is "x * 2 - 3.4" I want to read it with a CIN or something like that
You can't do that in c++. You have to (as you have already done) hard-code the function.
You might, perhaps, restrict the function to, say, a linear form "ax+b" and input the values of a and b. You might (if you have a lot of time on your hands) write your own interpreter that will deal with suitably-formatted expressions. However, you can't do what javascript does with the "eval()" function and actually enter a run-time function. And for all the flexibility of that javascript eval() function, it is also staggeringly dangerous, because you can actually enter any runnable code as well; (for example, code to wipe all your files). So there are very good reasons for c++ not allowing it.
You can also use eval() in Python:
1 2 3
s = input( "Enter an expression: " )
x = float( input( "Enter the value of x: " ) )
print( eval( s ) )
Enter an expression: 2*x+3
Enter the value of x: 5
13.0