entering math functions after i run the program in c++ or java or any other programming language , just need the idea Example 2x-3cos(30);
for C++: #include <iostream> #include <cmath> using namespace std; int main() { double x, a, result; cout << "Please enter a value for x: "; cin >> x; cout << "Please enter an angle: "; cin >> a; result = 2*x - 3*cos(a); cout << "2*" << x << " - 3*Cos(" << a << ") = " << result << endl; system("pause"); return 0; } Something like this will do what you want to do, but the angle will have to be entered in radians.
in Java there is the MATH api which allows you to use cos sin etc. First you would need to implement java.util.scanner to ask you an input. When you enter that input you can make it so that input it set through cos, sin, tan, etc....
you absolutely didnt get me , what u showed me here is basics i know , but what i am trying to do is changing the function itself for example #include <string > #include <iostream> using namespace std; void main () { cout << "please enter ur function \n"; string s; double x; only one variable "x" will be used in any function cin >> s; // suppose that the user entered 5*x-3*sin(x) cout << "enter x (value of your variable)"; cin >>x;//suppose that the used entered 5; } // now all the work will be done on 5 (5*5-3*sins(5)) , but the user could have entered the function( 2x+3) instead of (5*x-3*sin(x) ) or any function and value for X. hope u get me
Join our real-time social learning platform and learn together with your friends!