Question

In my application I have created a number pad that also has operators such as + - x /. All I want to know how to do is display these in a label when the user inputs them. For example if the user wanted to know 3 + 5, the user would push the button for each and the label would show 3 + 5 and then the user would push calculate and the answer would display in another label. So basically how do I display that all together in one label? I have been trying to do this a few different ways but it is just giving me a headache.

Was it helpful?

Solution

Track the user input by appending the operations to an NSArray. If the user taps the '+' button, add an NSString to the array of @"+", if they tap on "-", add an @"-" to the array. From here you can generate an concatenated NSString of all the operations to generate the equation.

Furthermore, as the operations are all stored in an NSArray, if the user taps the delete button, you just have to remove the last string from the array and regenerate the equation rather than have to perform string comparisons and manipulation to remove the operation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top