From 36ff7f8feffd1dbed2aa260312de5bb79620f563 Mon Sep 17 00:00:00 2001 From: redpois0n Date: Thu, 23 Jul 2015 21:04:51 +0200 Subject: [PATCH] Update shunting-yard.cpp --- shunting-yard.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/shunting-yard.cpp b/shunting-yard.cpp index 1c6672d..fef342d 100644 --- a/shunting-yard.cpp +++ b/shunting-yard.cpp @@ -1,6 +1,6 @@ // Source: http://www.daniweb.com/software-development/cpp/code/427500/calculator-using-shunting-yard-algorithm# // Author: Jesse Brown -// Modifications: Brandon Amos +// Modifications: Brandon Amos, redpois0n #include #include @@ -135,7 +135,7 @@ double calculator::calculate(const char* expr, opPrecedence["("] = -1; opPrecedence["<<"] = 1; opPrecedence[">>"] = 1; opPrecedence["+"] = 2; opPrecedence["-"] = 2; - opPrecedence["*"] = 3; opPrecedence["/"] = 3; + opPrecedence["*"] = 3; opPrecedence["/"] = 3; opPrecedence["%"] = 3; opPrecedence["^"] = 4; // 2. Convert to RPN with Dijkstra's Shunting-yard algorithm. @@ -170,6 +170,8 @@ double calculator::calculate(const char* expr, evaluation.push(pow(left, right)); } else if (!str.compare(">>")) { evaluation.push((int) left >> (int) right); + } else if (!str.compare("%")) { + evaluation.push(left % right); } else { throw std::domain_error("Unknown operator: '" + str + "'."); }