From 6297fec59984569016939ada1313aab6f38d65e1 Mon Sep 17 00:00:00 2001 From: Giuseppe Tornello Date: Mon, 3 Nov 2025 23:25:37 +0100 Subject: [PATCH 1/2] feat: implemented calculator --- exercises/calculator.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/exercises/calculator.cpp b/exercises/calculator.cpp index 013cc786..d3296ce8 100644 --- a/exercises/calculator.cpp +++ b/exercises/calculator.cpp @@ -10,3 +10,25 @@ Multiplication: 8 Division: 2 */ +#include +using namespace std; + +void Calculate(const int&, const int&); + +void Calculate(const int& n1, const int& n2){ + cout << "SUM: " << n1 + n2 << endl; + cout << "Difference: " << n1 - n2 << endl; + cout << "Multiplication: " << n1 * n2 << endl; + cout << "Division: " << n1 / n2 << endl; +} + +int main(){ + int num1 , num2; + cout << "Insert first number: "; + cin >> num1; + cout << "Insert second number: "; + cin >> num2; + + Calculate( num1 , num2 ); + return 0; +} From 015a90c8b1ff6dd3e6f585a1e3dc9e65f811fd92 Mon Sep 17 00:00:00 2001 From: Giuseppe Tornello Date: Tue, 4 Nov 2025 12:00:17 +0100 Subject: [PATCH 2/2] refactor: removed redundancy and added exit defines --- exercises/calculator.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exercises/calculator.cpp b/exercises/calculator.cpp index d3296ce8..0e51bb75 100644 --- a/exercises/calculator.cpp +++ b/exercises/calculator.cpp @@ -13,7 +13,8 @@ #include using namespace std; -void Calculate(const int&, const int&); +#define EXIT_SUCCESS 0 +#define EXIT_FAILURE 1 void Calculate(const int& n1, const int& n2){ cout << "SUM: " << n1 + n2 << endl; @@ -30,5 +31,5 @@ int main(){ cin >> num2; Calculate( num1 , num2 ); - return 0; + return EXIT_SUCCESS; }