Just need a point in the right direction
So I'm making this calculator, that deals with multiple calculations in one go.
expected input(currently only done + and *)
2 + 5 X 2; This should be 12(5*2 = 10 + 2 = 12);
Output:
20
Calc code:
So any pointers in what I'm doing wrong?Code:ArrayList a = new ArrayList(); ArrayList b = new ArrayList(); a.AddRange(tb.Text.Split('+')); double ret=0; for (int i=0; i < a.Count; i++) { if (a[i].ToString().Contains('X')) { b.AddRange(a[i].ToString().Split('X')); ret = 0; foreach (string s in b) { if (ret == 0) { ret = double.Parse(s); } else { ret = ret * double.Parse(s); } } a.Add(ret.ToString()); } if (!a[i].ToString().Contains('X')) { ret = ret + double.Parse(a[i].ToString()); } } return ret;




Reply With Quote