Hey,
Most of you who help in this forum have probably read my posts, and this is another one for my math bot. :)
I am using string arrays to assign to math operands, for example I would have an array such as this for a basic math equation:
5 * 2
The program will determine where any operators are, and split into an array eventually outputting this:
5,*,2.
The method I use to determine whether to assign the current string to a variable or an operator is determined by the index of the for each loop I am using.
So, for example, I would have this:
i=1;
foreach (string piece in substrings)
{
if((i-1)%2==0){//assign to B
}
if(i%2==0){//assign to operator string
}
if(i==1|((i-1)%3)==0){//assign to A
}
}
But so far, this code is not satisfactory to what I need it to do.
(Especially the last one, I messed it up and it doesn't work anyway so whatever)
if I have 5*2+7
The indexing is like this [1,'5'],[2,'*],[3,'2'],[4,'+'],[5,'7']
from there you can see what are numbers and what are operators, and I need the foreach code to identify from the index if it will assign the operand to an operator, A, or B using multiples, or any other system you guys may think up.
So, could someone create a foreach indexing code that will work for my needs?
Thanks.
P.S. Sorry if my explanation for my situation is a bit... messy but I hope you guys understand :D