How do I both allow a user to input some formula such as X + 1 then allow myself to use that formula to produce some output such as x = 3; 3+1 =4; output: 4?
Printable View
How do I both allow a user to input some formula such as X + 1 then allow myself to use that formula to produce some output such as x = 3; 3+1 =4; output: 4?
Uh, that's nat that simple!
You have to write a parser on your own. In the book "C++ Complete Reference", Herbert Schildt discribes how to write such a parser...
Are you the same one who's posted this question 3 times already? Do something like the following to parse the string entered by the user then use your favorite switch statement to do the calculation.
-PreludeCode:int main(){
char array[] = "x+x*3", *p = &array[0];
char y = '5';
while(*p != '\0'){
if(*p == 'x')
*p = y;
p++;
}
puts(array);
return 0;
}