From 7603b05b40606d341d055b95b8f7d344f0a11940 Mon Sep 17 00:00:00 2001 From: Katarzyna-W <39034151+Katarzyna-W@users.noreply.github.com> Date: Mon, 7 Jul 2025 13:00:24 +0200 Subject: [PATCH 1/7] Update calculate.hpp --- homework/calculate/calculate.hpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 7a933a25..5f595cd1 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -2,6 +2,17 @@ #include std::string calculate(const std::string& command, int first, int second) { - // TODO: Implement your solution here and return proper value - return ""; + std::string result; + if (command == "add"){ + result = std::to_string(first + second);} + else if (command == "substract"){ + result = std::to_string(first - second);} + else if (command == "multiply"){ + result = std::to_string(first * second);} + else if (command == "divide"){ + result = std::to_string(first / second);} + else{ + result = "Invalid input"; + } + return result; } From aa3a94ac6eb70a30263324730bdc89ca6f5a1fb8 Mon Sep 17 00:00:00 2001 From: Katarzyna-W <39034151+Katarzyna-W@users.noreply.github.com> Date: Mon, 7 Jul 2025 13:09:54 +0200 Subject: [PATCH 2/7] Update calculate.hpp --- homework/calculate/calculate.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 5f595cd1..bffa576f 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -4,13 +4,17 @@ std::string calculate(const std::string& command, int first, int second) { std::string result; if (command == "add"){ - result = std::to_string(first + second);} - else if (command == "substract"){ - result = std::to_string(first - second);} + result = std::to_string(first + second); + } + else if (command == "subtract"){ + result = std::to_string(first - second); + } else if (command == "multiply"){ - result = std::to_string(first * second);} + result = std::to_string(first * second); + } else if (command == "divide"){ - result = std::to_string(first / second);} + result = std::to_string(first / second); + } else{ result = "Invalid input"; } From c5ea738900ca7ec6bf38afcf0530231ee0e5eb3a Mon Sep 17 00:00:00 2001 From: Katarzyna-W <39034151+Katarzyna-W@users.noreply.github.com> Date: Mon, 7 Jul 2025 13:15:05 +0200 Subject: [PATCH 3/7] Update calculate.hpp --- homework/calculate/calculate.hpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index bffa576f..9b10564d 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -3,20 +3,16 @@ std::string calculate(const std::string& command, int first, int second) { std::string result; - if (command == "add"){ + if (command == "add") { result = std::to_string(first + second); - } - else if (command == "subtract"){ + } else if (command == "subtract") { result = std::to_string(first - second); - } - else if (command == "multiply"){ + } else if (command == "multiply") { result = std::to_string(first * second); - } - else if (command == "divide"){ + } else if (command == "divide") { result = std::to_string(first / second); - } - else{ - result = "Invalid input"; + } else { + result = "Invalid data"; } return result; } From 749eb5e982474dce811dece4ea22776f2ac6b505 Mon Sep 17 00:00:00 2001 From: Katarzyna-W <39034151+Katarzyna-W@users.noreply.github.com> Date: Mon, 7 Jul 2025 13:18:21 +0200 Subject: [PATCH 4/7] Update calculate.hpp --- homework/calculate/calculate.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 9b10564d..9313ed12 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -10,7 +10,11 @@ std::string calculate(const std::string& command, int first, int second) { } else if (command == "multiply") { result = std::to_string(first * second); } else if (command == "divide") { - result = std::to_string(first / second); + if (second == 0) { + result = "Division by 0"; + } else { + result = std::to_string(first / second); + } } else { result = "Invalid data"; } From 83387208bbdb45abd1c9fc906d3ead5ca1483aa0 Mon Sep 17 00:00:00 2001 From: Katarzyna-W <39034151+Katarzyna-W@users.noreply.github.com> Date: Mon, 7 Jul 2025 13:20:09 +0200 Subject: [PATCH 5/7] Update calculate.hpp --- 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 9313ed12..108b9284 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -3,11 +3,11 @@ std::string calculate(const std::string& command, int first, int second) { std::string result; - if (command == "add") { + if (command == "add") { result = std::to_string(first + second); } else if (command == "subtract") { result = std::to_string(first - second); - } else if (command == "multiply") { + } else if (command == "multiply") { result = std::to_string(first * second); } else if (command == "divide") { if (second == 0) { From f885cbc587ac6e414b67a2a9fe34c9dd0287c9e5 Mon Sep 17 00:00:00 2001 From: Katarzyna-W <39034151+Katarzyna-W@users.noreply.github.com> Date: Mon, 7 Jul 2025 15:33:46 +0200 Subject: [PATCH 6/7] Update calculate.hpp From 730ee6a347efde35504e50302d0776d7d2355e03 Mon Sep 17 00:00:00 2001 From: Katarzyna-W <39034151+Katarzyna-W@users.noreply.github.com> Date: Mon, 7 Jul 2025 15:41:17 +0200 Subject: [PATCH 7/7] Update calculate.hpp