From cdda26f5235c654eb2f4d4205f3c144ba9ee9afe Mon Sep 17 00:00:00 2001 From: MichalG315 Date: Thu, 17 Jul 2025 21:45:01 +0200 Subject: [PATCH 1/5] Invalid data works --- homework/calculate/calculate.hpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 7a933a25..466edf20 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -2,6 +2,21 @@ #include 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 ""; + } + + else if (command == "substract") { + return ""; + } + + else if (command == "multiply") { + return ""; + } + + else if (command == "divide") { + return ""; + } else { + return "Invalid data"; + } } From 152a4563bca87c48eeaa4a5f4daa12f6adc422b6 Mon Sep 17 00:00:00 2001 From: MichalG315 Date: Thu, 17 Jul 2025 21:49:53 +0200 Subject: [PATCH 2/5] add works --- homework/calculate/calculate.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 466edf20..712431a2 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -3,7 +3,7 @@ std::string calculate(const std::string& command, int first, int second) { if (command == "add") { - return ""; + return std::to_string(first + second); } else if (command == "substract") { From 2b173f8a8d07dc537f7bd8f8cc044f815a204a74 Mon Sep 17 00:00:00 2001 From: MichalG315 Date: Thu, 17 Jul 2025 21:51:14 +0200 Subject: [PATCH 3/5] subtract works --- homework/calculate/calculate.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 712431a2..cbb92864 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -6,8 +6,8 @@ std::string calculate(const std::string& command, int first, int second) { return std::to_string(first + second); } - else if (command == "substract") { - return ""; + else if (command == "subtract") { + return std::to_string(first - second); } else if (command == "multiply") { From 1b578172d67cc01ce4d15384e97c7aa34447bac2 Mon Sep 17 00:00:00 2001 From: MichalG315 Date: Thu, 17 Jul 2025 21:52:01 +0200 Subject: [PATCH 4/5] multiply works --- homework/calculate/calculate.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index cbb92864..829eab7a 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -11,7 +11,7 @@ std::string calculate(const std::string& command, int first, int second) { } else if (command == "multiply") { - return ""; + return std::to_string(first * second); } else if (command == "divide") { From 10520794f89f08a19657d18bb1ecd85b7b20a338 Mon Sep 17 00:00:00 2001 From: MichalG315 Date: Thu, 17 Jul 2025 21:57:07 +0200 Subject: [PATCH 5/5] dividing works --- homework/calculate/calculate.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 829eab7a..67b75008 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -15,7 +15,10 @@ std::string calculate(const std::string& command, int first, int second) { } else if (command == "divide") { - return ""; + if (second == 0) { + return "Division by 0"; + } + return std::to_string(first / second); } else { return "Invalid data"; }