...meaning: if you have a function that computes x:

```
int Solve2xMinusxPlus4x(int x)
{
return ((2*x) - x + (4*x));
}
```

...you could loop a call to that until you receive the answer you want.

If you test it by looping from 0 to 10, you would eventually (at 1) receive the answer 5.

The x would drop off of the equation because you are solving FOR x.

no there is no = sign, just x's. and also we dont know that user will enter 2x-x+4x. ever time user will enter different stuff. for ex user

can enter -2x+x, or 4x-2x-3-x-x+4x or -x+2x.

the code that enter above it works if there are no x's. and i dont know how to do it will x's

my think was if i remove all the x's by using for loop and seting x to \0. but it dont really work if user enter -x-2x.

traverse the array using a loop

when a character x is found convert the digit before the x using atoi() then save it temporarily to a variable then check the operation after the "x" after that check the next elements for the x and do the same

for example:

2x+3x

traverse the loop

when an x is found

convert and save 2 (the element before x)

check the operation (+) (make a condition for all operations)

check the set after the operator

check if the there is another x

convert and save 3

solve the current operation (3+2) and save the answer

continue traversing the array until the end of the array is found

anything else you need to be aware of are digits that doesn't have an x with them or x that is not preceded by a digit so the default should be 1 and finally negative numbers

**note**: I once did a similar program like this with algebraic equations but I used linked lists instead of arrays so I can have a better control of the elements but I believe the concept should be about similar...also coding this would be longer than the code you posted so good luck :)

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled OP Sponsor or OP Kudos