Skip to content
Snippets Groups Projects
Commit 97afae57 authored by Michael Schneider's avatar Michael Schneider
Browse files

added modulo function

parent cc421445
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ int plus( int a, int b) { return a + b; }
int minus( int a, int b) { return a - b; }
int multiply(int a, int b) { return a * b; }
int divide( int a, int b) { return a / b; }
int modulo( int a, int b) { return a % b; }
int pop_stack(auto &stack) {
const auto ret{stack.top()};
......@@ -29,6 +30,7 @@ int evaluate(const std::string &s) {
case '-': change_stack_state(minus, stack); break;
case '*': change_stack_state(multiply, stack); break;
case '/': change_stack_state(divide, stack); break;
case '%': change_stack_state(modulo, stack); break;
case '0'...'9': stack.push(c - '0'); break;
}
}
......
......@@ -5,4 +5,5 @@
TEST_CASE( "some example calculations", "[calc]") {
REQUIRE( evaluate("11+") == 2 );
REQUIRE( evaluate("12+2-3*") == 3 );
REQUIRE( evaluate("32%") == 1 );
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment