I'm writing a program for a console calculator. Something where the user types in 2 + 2 x 2 + 6/2 = and my program returns the answer.
In the program
-an iterator goes through the private member string, and when it encounters a number, it puts it into the stack.
-when it encounters an operator, say +, it calls the
code]add([pop stack], nextNumber(int positionOfIterator));[/code]
-the nextNumber function handles BODMAS. It will use the position of the iterator, and find the next number. If the number is being divided or multiplied first, it will solve those first, and return this number.
-the added number is put at the top of the stack.
My question is what function can I use to return the position of the iterator. I could, of course, have a position variable which tracks the position of the iterator through the string, and I could pass this integer to the nextNumber function - but that seems kind of sloppy. So what's a more eloquent way of doing it.