From 9b9d50eca7dbbe6cbf0dd0b1c5dcca77195ffeeb Mon Sep 17 00:00:00 2001 From: schlumphi Date: Tue, 3 Feb 2026 21:14:14 +0100 Subject: [PATCH 1/2] feat: calculator --- homework/calculate/calculate.hpp | 34 ++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 7a933a25..1ab8d0ec 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -1,7 +1,37 @@ #pragma once #include +auto add(const int lhs, const int rhs) -> std::string { + return std::to_string(lhs + rhs); +} + +auto subtract(const int lhs, const int rhs) -> std::string { + return std::to_string(lhs - rhs); +} + +auto multiply(const int lhs, const int rhs) -> std::string { + return std::to_string(lhs * rhs); +} + +auto divide(const int lhs, const int rhs) -> std::string { + if (rhs != 0) { + return std::to_string(lhs / rhs); + } + return "Division by 0"; +} + std::string calculate(const std::string& command, int first, int second) { - // TODO: Implement your solution here and return proper value - return ""; + if (command == "add") { + return add(first, second); + } + else if (command == "subtract") { + return subtract(first, second); + } + else if (command == "multiply") { + return multiply(first, second); + } + else if (command == "divide") { + return divide(first, second); + } + return "Invalid data"; } From 6cdc8f9e381ad11360d74b5f374add5fc6b1e128 Mon Sep 17 00:00:00 2001 From: schlumphi Date: Tue, 3 Feb 2026 21:25:28 +0100 Subject: [PATCH 2/2] style: changed code formatting --- homework/calculate/calculate.hpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 1ab8d0ec..cb7e7877 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -23,14 +23,11 @@ auto divide(const int lhs, const int rhs) -> std::string { std::string calculate(const std::string& command, int first, int second) { if (command == "add") { return add(first, second); - } - else if (command == "subtract") { + } else if (command == "subtract") { return subtract(first, second); - } - else if (command == "multiply") { + } else if (command == "multiply") { return multiply(first, second); - } - else if (command == "divide") { + } else if (command == "divide") { return divide(first, second); } return "Invalid data";