|
|
> What you could do, is have a function like DoOperation(stack,op), and use
> "op" as a token for the operation.
> if (cmd == "+") {DoOP(stack,0); continue;}
> if (cmd == "-") {DoOP(stack,1); continue;}
> if (cmd == "/") {DoOP(stack,2); continue;}
> if (cmd == "*") {DoOP(stack,3); continue;}
This is good, but instead of using integers like 0 1 2 3, I'd use an enum:
enum Operation
{
OP_ADD,
OP_SUBTRACT,
OP_DIVIDE,
OP_MULTIPLY,
};
An enum gives meaning to this sort of approach so you don't have to remember
what something like "2" means.
- Slime
[ http://www.slimeland.com/ ]
Post a reply to this message
|
|