From 11abb1221d75cad0e67a288fd3997a8cb16a8cb0 Mon Sep 17 00:00:00 2001 From: Josseye <155636321+Josseye@users.noreply.github.com> Date: Tue, 9 Jan 2024 21:10:08 +0100 Subject: [PATCH 1/8] Update calculate.hpp --- homework/calculate/calculate.hpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 7a933a25..ca3cf8ec 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -1,7 +1,16 @@ #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") + return std::to_string(first + second); + else if (command == "substract") + return std::to_string(first - second); + else if (command == "multiply") + return std::to_string(first * second); + else if (command == "divide") + return std::to_string(first / second); + else + return "Invalid data"; } From 37c2b2e15a329c181a8b9ae8828cf4cb936c77fa Mon Sep 17 00:00:00 2001 From: Josseye <155636321+Josseye@users.noreply.github.com> Date: Tue, 9 Jan 2024 21:14:36 +0100 Subject: [PATCH 2/8] Update calculate.hpp --- homework/calculate/calculate.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index ca3cf8ec..146605bc 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -1,8 +1,7 @@ #pragma once #include -std::string calculate(const std::string& command, int first, int second) - { +std::string calculate(const std::string& command, int first, int second) { if (command == "add") return std::to_string(first + second); else if (command == "substract") From 11a75611cf1c12535e2a22f98904b888b1663c67 Mon Sep 17 00:00:00 2001 From: Josseye <155636321+Josseye@users.noreply.github.com> Date: Tue, 9 Jan 2024 21:27:46 +0100 Subject: [PATCH 3/8] Update calculate.hpp --- homework/calculate/calculate.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 146605bc..c4c4215f 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -1,15 +1,16 @@ #pragma once #include -std::string calculate(const std::string& command, int first, int second) { +std::string calculate(const std::string& command, int first, int second) + { if (command == "add") - return std::to_string(first + second); + return std::to_string(first + second); else if (command == "substract") - return std::to_string(first - second); + return std::to_string(first - second); else if (command == "multiply") - return std::to_string(first * second); + return std::to_string(first * second); else if (command == "divide") - return std::to_string(first / second); + return std::to_string(first / second); else return "Invalid data"; } From 5c5b9f2157ef9460611716b4dbee222e5983cbdb Mon Sep 17 00:00:00 2001 From: Josseye <155636321+Josseye@users.noreply.github.com> Date: Tue, 9 Jan 2024 21:29:33 +0100 Subject: [PATCH 4/8] Update calculate.hpp --- homework/calculate/calculate.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index c4c4215f..08e6613b 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -1,8 +1,7 @@ #pragma once #include -std::string calculate(const std::string& command, int first, int second) - { +std::string calculate(const std::string& command, int first, int second) { if (command == "add") return std::to_string(first + second); else if (command == "substract") From f3c3e4e25566f52e86cf43a1b7535b74f24d035a Mon Sep 17 00:00:00 2001 From: Josseye <155636321+Josseye@users.noreply.github.com> Date: Tue, 9 Jan 2024 21:49:56 +0100 Subject: [PATCH 5/8] Update calculate.hpp --- homework/calculate/calculate.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 08e6613b..fe122e60 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -1,15 +1,16 @@ #pragma once #include -std::string calculate(const std::string& command, int first, int second) { +sstd::string calculate(const std::string& command, int first, int second) { if (command == "add") return std::to_string(first + second); else if (command == "substract") return std::to_string(first - second); else if (command == "multiply") return std::to_string(first * second); - else if (command == "divide") - return std::to_string(first / second); + else if (command == "divide"){ + if (second==0) return "Division by 0"; + else return std::to_string(first / second);} else return "Invalid data"; } From 6556bee697d6f3da39cc8f24b29f5ab8959c338e Mon Sep 17 00:00:00 2001 From: Josseye <155636321+Josseye@users.noreply.github.com> Date: Tue, 9 Jan 2024 21:57:19 +0100 Subject: [PATCH 6/8] Update calculate.hpp --- homework/calculate/calculate.hpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index fe122e60..64a07364 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -1,16 +1,18 @@ #pragma once #include -sstd::string calculate(const std::string& command, int first, int second) { +std::string calculate(const std::string& command, int first, int second) { if (command == "add") return std::to_string(first + second); else if (command == "substract") return std::to_string(first - second); else if (command == "multiply") return std::to_string(first * second); - else if (command == "divide"){ - if (second==0) return "Division by 0"; - else return std::to_string(first / second);} - else - return "Invalid data"; -} + else if (command == "divide") { + if (second == 0) + return "Division by 0"; + else + return std::to_string(first / second); + } else + return "Invalid data"; + } From a4bd3777462dd25c063bc6cd6fbbd099d5cbca55 Mon Sep 17 00:00:00 2001 From: Josseye <155636321+Josseye@users.noreply.github.com> Date: Tue, 9 Jan 2024 22:00:24 +0100 Subject: [PATCH 7/8] 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 64a07364..20e89931 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -14,5 +14,5 @@ std::string calculate(const std::string& command, int first, int second) { else return std::to_string(first / second); } else - return "Invalid data"; - } + return "Invalid data"; +} From e26fadbb2d286e45338ef6b6d473e9498b8772d8 Mon Sep 17 00:00:00 2001 From: Josseye <155636321+Josseye@users.noreply.github.com> Date: Wed, 10 Jan 2024 15:30:33 +0100 Subject: [PATCH 8/8] Update calculate.hpp --- 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 20e89931..44e3c4e8 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -4,7 +4,7 @@ std::string calculate(const std::string& command, int first, int second) { if (command == "add") return std::to_string(first + second); - else if (command == "substract") + else if (command == "subtract") return std::to_string(first - second); else if (command == "multiply") return std::to_string(first * second);