From 8dfb066039ac8c8cc48925d76bc58a2af4b7ce5e Mon Sep 17 00:00:00 2001 From: Sebastian Sosnowski Date: Tue, 6 Jan 2026 14:37:53 +0100 Subject: [PATCH 1/2] Implement calculate function --- homework/calculate/calculate.hpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 7a933a25..c2e62bd6 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -2,6 +2,20 @@ #include std::string calculate(const std::string& command, int first, int second) { - // TODO: Implement your solution here and return proper value - return ""; + std::string res{}; + + if (command == "add") { + res = std::to_string(first + second); + } else if (command == "subtract") { + res = std::to_string(first - second); + } else if (command == "multiply") { + res = std::to_string(first * second); + } else if (command == "divide") { + if (second == 0) + return "Division by 0"; + res = std::to_string(first / second); + } else { + res = "Invalid data"; + } + return res; } From 9d46c0a2de8a5d44622728e8700018815bf6cd59 Mon Sep 17 00:00:00 2001 From: Sebastian Sosnowski Date: Tue, 6 Jan 2026 17:15:45 +0100 Subject: [PATCH 2/2] Fix --- homework/calculate/calculate.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index c2e62bd6..90470a00 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -2,20 +2,20 @@ #include std::string calculate(const std::string& command, int first, int second) { - std::string res{}; + std::string result{}; if (command == "add") { - res = std::to_string(first + second); + result = std::to_string(first + second); } else if (command == "subtract") { - res = std::to_string(first - second); + result = std::to_string(first - second); } else if (command == "multiply") { - res = std::to_string(first * second); + result = std::to_string(first * second); } else if (command == "divide") { if (second == 0) return "Division by 0"; - res = std::to_string(first / second); + result = std::to_string(first / second); } else { - res = "Invalid data"; + result = "Invalid data"; } - return res; + return result; }