Today is September 6. Came to the 14th day of Lan Yi. Miss Liu did not speak a new lesson today, but led us to do a premium version of the calculator. I also made a simple calculator for the last two days in the two edition. But today, after listening to the teacher's explanation, found that their own code has a lot of too cumbersome place. Lots of things to know about improvement. There is also the discovery of the first two days of the code has been somewhat forgotten. For example, how to replace the data in the array and how to stitch the string changes. And the biggest harvest today is how to achieve the priority calculation.
for (int i=0; i<self.) operators. Count; i++) {
nsstring *operator = self. operators [i];
if ([operator isequaltostring:@ "x"]| | [Operator isequaltostring:@ "÷"]) {
float number1 = [self. Numbers[i] floatvalue];
float number2 = [self. Numbers[i+1] floatvalue];
float result = 0;
if ([operator isequaltostring:@ "x"]) {
result = Number1 * NUMBER2;
}Else{
result = Number1/number2;
}
// Remove The number of two operations and insert the results back into the
[Self. numbers removeobjectatindex: i];
[Self. numbers removeobjectatindex: i];
[Self. numbers insertobject:@ (result) atindex: i];
// Delete the current operator
[Self. operators removeobjectatindex: i];
// to ensure that every symbol in the array is traversed
i--;
}
}
There is today in the work of the teacher left to find that there are many details of the poor handling, to find a bug wasted a long time. Will certainly be improved in the future.
Lan Yi Education 14th Day record