Answer the question
In order to leave comments, you need to log in
How to make a string parser?
Square root calculator.
The problem is that I can't do "square root" because you have to enter x first and then y. And if I just describe it as x = sqrt(x), then you still need to enter both x and y. I can't figure out what's wrong.
- (IBAction)operation:(id)sender {
if (yFlag && !enterFlag) {
switch (operation) {
case plusOperation:
x = y + x;
break;
case minusOperation:
x = y - x;
break;
case multiplyOperation:
x = y * x;
break;
case divisionOperation:
x = y / x;
break;
case degreeOperation:
x = pow(y, x);
break;
// вот тут проблема
case radicalOperation:
x = sqrt(x);
break;
default:
break;
}
}
y = x;
enterFlag = YES;
yFlag = YES;
operation = [sender tag];
[self calcScreen];
}
Answer the question
In order to leave comments, you need to log in
In the context of a calculator, you need to parse the string into reverse polish .
Examples:
www.interface.ru/home.asp?artId=1492
ru.wikiversity.org/wiki/%D0%9E%D0%B1%D1%80%D0%B0%D...
habrahabr.ru/post/ 50158
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question