> "5x^4-3x^2+12x-6"
Step 1 is write a function which tokenises the string to
5x^4
-3x^2
+12x
-6
x by itself is x^1
the constant is -6x^0
Then split each one of those up into two values, and store them in say
Code:
struct foo {
int scale;
int power;
} terms[10];
From which you get, as you parse each term
Code:
term[0].scale = 5;
term[0].power = 4;
term[1].scale = -3;
term[1].power = 2;
term[2].scale = 12;
term[2].power = 1;
term[3].scale = -6;
term[3].power = 0;
Then it's simply a matter of inputting a value for x, and looping over those terms to do
Code:
sum += term[i].scale * pow( x, term[i].power );