From 9948d80ffa4315e809690d69342ac7953d21371e Mon Sep 17 00:00:00 2001 From: Radoslaw Marcinowski Date: Mon, 26 May 2025 14:20:57 +0200 Subject: [PATCH] Initial implementation of calculate() --- homework/calculate/calculate.hpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 7a933a25..924ccc38 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -2,6 +2,19 @@ #include std::string calculate(const std::string& command, int first, int second) { - // TODO: Implement your solution here and return proper value - return ""; + if (0 == command.compare("add")) { + return std::to_string(first + second); + } else if (0 == command.compare("subtract")) { + return std::to_string(first - second); + } else if (0 == command.compare("multiply")) { + return std::to_string(first * second); + } else if (0 == command.compare("divide")) { + if (0 != second) { + return std::to_string(first / second); + } else { + return "Division by 0"; + } + } else { + return "Invalid data"; + } }