this is the first time I am posting in this site. I have been here for almost 3 months looking for answers in my C++ problems.
I do have this problem that I cannot solve, and I think has not been done before.
here's some type of code for this.
cout << "Enter value of x: " << endl; //Let's say 5.
cin >> x;
cout << "Enter equation: "; //Let's say x+1
cin >> equation;
Then the program analyzes that this character "x" has an initial value of 5.
I already have the parser for the equation functions (+,-,*,/)
This is the only thing lacking. Is there some type of function that i missed?
Note: I am not majoring in C++. I only need C++ to accept equations because we will be using such in solving equations. :( (i dont know why our prof wanted us to use C++ instead of MATLAB.)
I need this code to stop acting weird when i am inputting x or X..
Can you help me?
In function void analyzer::bomb( double &culmination ) added case VARIABLE:
1 2 3 4 5 6 7
case VARIABLE:
{
std::cout << "looking up value of variable '" << token << "' => assuming result == 999\n" ;
culmination = 999 ; // *** hard-coded *** TODO: look up symbol table, get the actual value
nextToken();
return ;
}
In function void analyzer::serror( int error ) line 202:
1 2
// static char *e[] = // ****
staticconstchar *e[] = // literal strings are arrays of const char
In function int analyzer::isdelim( char c ) line 254:
1 2
//if( strchr( " +-/*%^=()x", c ) || c == 9 || c == '\r' || c == 0 ) // ***
if( strchr( " +-/*%^=()", c ) || c == 9 || c == '\r' || c == 0 ) // identifier 'x' is not a delimiter
In function int main() lines 288-293:
1 2 3 4 5 6 7 8
if( *expstr == '.' )
{
// equation.~analyzer(); // *** avoid this
// instead, move the definition of equation into the loop
// a new analyser object will be created each time through the loop
break; // Infinite loop exited by typing a period.
}
Thank you very much JLBorges. :)
I appreciate your help. Mwuaaaaaaahhhh. :D
Will this be the same if I am going to edit this to parse trigonometric functions, logarithmic functions, inverse hyperbolic functions., etc..
Example:
if x = 3.1416/2
INPUT: 2*x+tan(x)
Should have an output something like this..
4.1416
Edit: I think I just need to input something like codes,
Example: L is for log10
S is for sine function
C is for cosine,
T for Trigonometric function, so on.. :)
Huhuhuuhuh.. It's eating all the RAM i my head >.<