Ok people,

I am a maths teacher. I teach simple highschool maths. Kids always seem to have problems with algebra. They struggle to apply the rules of 'BODMAS' in order to solve an equation.

I want to create a general algebra solver using c++! Sounds pretty daunting I know. But I know it can be done. An example would be to create a program to solve:

6(x+2)+ x/2= 5(x+1)

And before anyone writes in saying use a 'scientific calculator' - this is not what I want. Specifically, the program should show each line applying the rules of 'BODMAS' so....

1. 6x+ 12 + x/2 = 5x+5 Expand brackets

2. 2(6x+12) +x = 2(5x+5) Multiply of the bottom

3. 12x+ 24 + x = 10x +10 Expand brackets again

4. 12x +x -10x = 10 -24 Collect x terms on LHS

5. 3x = -14 simplify

6. x = -14/3 factorise out x and solve.

In order to do this I reckon you would need to create several functions. Namely;

'Add_subtract _terms'

' Multiply_off_bottom'

'Expand_brackets'

'Separate 'x' onto LHS'

'Factorise out x'

What's more the program should be able to recognise 'terms'. Not just terms involving 'x' but any other letters, 'n', 'xyz' etc.

Here's what i got so far (not much I know)

Code:#include <iostream> #include <stdlib.h> #include <string.h> using namespace std; int main() { char count[81]; char store[81]; int freq[81]; char array[81][81]; int size_a; int freq_counter; int array_counter; cout<<"Please enter equation:"<<endl; cin>>store; size_a=strlen(store); //counts terms automatically int count_terms=1; for (int a=0; a<size_a; a++) { if (store[a]=='+') { count_terms++; } if(store[a]=='=') { count_terms++; } if (store[a]=='-') { count_terms++; } } for (int a=0; a<count_terms; a++) { cout<<"Enter each term"<<endl; cin>>count; int size=strlen(count); freq[a]=size; cout<<freq[a]<<endl; } cout<<""<<endl; //store[81]='-4x+2y-x-2' //store each term in a 2-d array int counter =0; for (int b=0; b<count_terms; b++) { for (int c=0; c<freq[b]; c++) { array[b][c]=store[counter]; counter++; } } // like term count // x = 2, found in array [0][-],[2][-] *sum these* // y = 1, found in array [1][-] // number = 1, found in array [3][-] // Need letter freq count!!! cout<<array[0][1]; system("PAUSE"); return 0; }