From 330fef55e4693a735314de7dc071e3a7049eca9d Mon Sep 17 00:00:00 2001 From: Konrad Legutko Date: Wed, 9 Sep 2026 18:49:51 +0000 Subject: [PATCH 1/2] [feat] Implementation of calculate --- homework/calculate/calculate.hpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 7a933a25..69e9a190 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -1,7 +1,29 @@ #pragma once #include -std::string calculate(const std::string& command, int first, int second) { - // TODO: Implement your solution here and return proper value - return ""; +std::string calculate(const std::string& command, int first, int second) +{ + if(command == "add") + { + int result = first + second; + return std::to_string(result); + } + else if(command == "subtract") + { + int result = first - second; + return std::to_string(result); + } + else if(command == "multiply") + { + int result = first * second; + return std::to_string(result); + } + else if(command == "divide") + { + if(second == 0) + return "Division by 0"; + int result = first / second; + return std::to_string(result); + } + return "Invalid data"; } From acc3ffc26351c4db3f63eeb4d3d63cdf2a40b814 Mon Sep 17 00:00:00 2001 From: Konrad Legutko Date: Wed, 9 Sep 2026 18:52:35 +0000 Subject: [PATCH 2/2] [fix] formatting --- homework/calculate/calculate.hpp | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 69e9a190..e8396dd6 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -1,29 +1,21 @@ #pragma once #include -std::string calculate(const std::string& command, int first, int second) -{ - if(command == "add") - { - int result = first + second; +std::string calculate(const std::string& command, int first, int second) { + if (command == "add") { + int result = first + second; return std::to_string(result); - } - else if(command == "subtract") - { - int result = first - second; + } else if (command == "subtract") { + int result = first - second; return std::to_string(result); - } - else if(command == "multiply") - { - int result = first * second; + } else if (command == "multiply") { + int result = first * second; return std::to_string(result); - } - else if(command == "divide") - { - if(second == 0) + } else if (command == "divide") { + if (second == 0) return "Division by 0"; - int result = first / second; + int result = first / second; return std::to_string(result); } return "Invalid data"; -} +} \ No newline at end of file