From dd1002a4e3bb60942d6445863b19d6085b649cc9 Mon Sep 17 00:00:00 2001 From: Philip Hart Date: Tue, 14 Jul 2026 13:49:00 +0200 Subject: [PATCH] implement calculate --- homework/calculate/calculate.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 7a933a25..06efef4b 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -3,5 +3,25 @@ std::string calculate(const std::string& command, int first, int second) { // TODO: Implement your solution here and return proper value + if (command == "add") { + return std::to_string(first + second); + } + else if (command == "subtract") { + return std::to_string(first - second); + } + else if (command == "multiply") { + return std::to_string(first * second); + } + else if (command == "divide") { + if (second != 0) { + return std::to_string(first / second); + } else { + return "Division by 0"; + } + } + else { + return "Invalid data"; + } + return ""; }