I tried taking the factorial "implementation" up and down but *
(multiplication) and /
(division) always comes before it. For example, if I enter 2*3!
, I want the computer to read 2*(3!)
not (2*3)!
. The computer produces (2*3)!
I have tried switching (up and down the code) where the factorial is but that is not doing the trick.
switch (t.kind) {
case '!': {
double d = left;
left = 1;
double limit = d;
for (int i = 0; i < limit; ++i) {
left *= d;
d = d - 1;
}
t = ts.get();
break;
}
case '/': {
double d = primary();
if (d == 0) error("division by zero");
left /= d;
t = ts.get();
break;
}
case '*':
left *= primary();
t = ts.get();
break;
default:
ts.putback(t);
return left;
}
}