From 882c0c616e2fbdf360fefc949c498ef6b1b83dfe Mon Sep 17 00:00:00 2001 From: Giuseppe Tornello Date: Mon, 3 Nov 2025 22:19:53 +0100 Subject: [PATCH 1/8] feat: implemented sum --- exercises/sum.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/exercises/sum.cpp b/exercises/sum.cpp index 0dcca937..bfe289df 100644 --- a/exercises/sum.cpp +++ b/exercises/sum.cpp @@ -6,3 +6,14 @@ Insert the second number: 2 Sum: 3 */ +#include +using namespace std; + +int main(){ + int num1,num2; + cout << "Insert the first number: " << endl; + cin >> num1; + cout << "Insert the second number: " << endl; + + cout << "Sum: " << num1 + num2 << endl; +} \ No newline at end of file From fbeed7489d339545f63188a1e5eda49ad5fdbea5 Mon Sep 17 00:00:00 2001 From: Giuseppe Tornello Date: Mon, 3 Nov 2025 22:21:00 +0100 Subject: [PATCH 2/8] fix: missing num2 input --- exercises/sum.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/sum.cpp b/exercises/sum.cpp index bfe289df..f1ffef7f 100644 --- a/exercises/sum.cpp +++ b/exercises/sum.cpp @@ -14,6 +14,7 @@ int main(){ cout << "Insert the first number: " << endl; cin >> num1; cout << "Insert the second number: " << endl; + cin >> num2; cout << "Sum: " << num1 + num2 << endl; } \ No newline at end of file From 0ca6684f78bd0fb570b6b82d0778b0c8af02f118 Mon Sep 17 00:00:00 2001 From: Giuseppe Tornello Date: Mon, 3 Nov 2025 22:30:54 +0100 Subject: [PATCH 3/8] refactor: let getNumInput handle number insertion --- exercises/sum.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/exercises/sum.cpp b/exercises/sum.cpp index f1ffef7f..d38a76c7 100644 --- a/exercises/sum.cpp +++ b/exercises/sum.cpp @@ -9,12 +9,16 @@ #include using namespace std; -int main(){ - int num1,num2; +void getNumInput(int* num){ cout << "Insert the first number: " << endl; - cin >> num1; + cin >> num[0]; cout << "Insert the second number: " << endl; - cin >> num2; + cin >> num[1]; +} + +int main(){ + int number[2]; + getNumInput(number); - cout << "Sum: " << num1 + num2 << endl; + cout << "Sum: " << number[0] + number[1] << endl; } \ No newline at end of file From f6d1954dfb6460830110b2708f0af25890d6d4a0 Mon Sep 17 00:00:00 2001 From: Giuseppe Tornello Date: Mon, 3 Nov 2025 22:36:34 +0100 Subject: [PATCH 4/8] refactor: implemented a template function to print the sum --- exercises/sum.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/exercises/sum.cpp b/exercises/sum.cpp index d38a76c7..410ef8a8 100644 --- a/exercises/sum.cpp +++ b/exercises/sum.cpp @@ -16,9 +16,12 @@ void getNumInput(int* num){ cin >> num[1]; } +template void printSum(const T& n1, const T& n2){ + cout << "Sum: " << n1 + n2 << endl; +} + int main(){ int number[2]; getNumInput(number); - - cout << "Sum: " << number[0] + number[1] << endl; + printSum(number[0],number[1]); } \ No newline at end of file From bc3f259f1195a2e21a618816ebe60fce7bdea427 Mon Sep 17 00:00:00 2001 From: Giuseppe Tornello Date: Mon, 3 Nov 2025 22:37:07 +0100 Subject: [PATCH 5/8] fix: missing return statement --- exercises/sum.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/exercises/sum.cpp b/exercises/sum.cpp index 410ef8a8..1ba5bdea 100644 --- a/exercises/sum.cpp +++ b/exercises/sum.cpp @@ -24,4 +24,5 @@ int main(){ int number[2]; getNumInput(number); printSum(number[0],number[1]); + return 0; } \ No newline at end of file From a7b6157fbcc60dd28083a903f39fdd4e80757c66 Mon Sep 17 00:00:00 2001 From: Giuseppe Tornello Date: Mon, 3 Nov 2025 22:45:00 +0100 Subject: [PATCH 6/8] chore: added function prototype and improved readability --- exercises/sum.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/exercises/sum.cpp b/exercises/sum.cpp index 1ba5bdea..b82d8adb 100644 --- a/exercises/sum.cpp +++ b/exercises/sum.cpp @@ -9,6 +9,9 @@ #include using namespace std; +void getNumInput(int* num); +template void printSum(const T& n1, const T& n2); + void getNumInput(int* num){ cout << "Insert the first number: " << endl; cin >> num[0]; @@ -23,6 +26,6 @@ template void printSum(const T& n1, const T& n2){ int main(){ int number[2]; getNumInput(number); - printSum(number[0],number[1]); + printSum( number[0] , number[1] ); return 0; } \ No newline at end of file From ac698548cad3b564d517b29bd1bb26696a96d238 Mon Sep 17 00:00:00 2001 From: Giuseppe Tornello Date: Tue, 4 Nov 2025 11:52:42 +0100 Subject: [PATCH 7/8] refactor: added exit defines --- exercises/sum.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/exercises/sum.cpp b/exercises/sum.cpp index b82d8adb..5e13438d 100644 --- a/exercises/sum.cpp +++ b/exercises/sum.cpp @@ -9,6 +9,9 @@ #include using namespace std; +#define EXIT_SUCCESS 1 +#define EXIT_FAILURE 0 + void getNumInput(int* num); template void printSum(const T& n1, const T& n2); @@ -27,5 +30,5 @@ int main(){ int number[2]; getNumInput(number); printSum( number[0] , number[1] ); - return 0; + return EXIT_SUCCESS; } \ No newline at end of file From 2146cb335ddba33a92a0d4083b4490659d9f015b Mon Sep 17 00:00:00 2001 From: Giuseppe Tornello Date: Tue, 4 Nov 2025 11:53:30 +0100 Subject: [PATCH 8/8] Ops --- exercises/sum.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/sum.cpp b/exercises/sum.cpp index 5e13438d..a0f809f8 100644 --- a/exercises/sum.cpp +++ b/exercises/sum.cpp @@ -9,8 +9,8 @@ #include using namespace std; -#define EXIT_SUCCESS 1 -#define EXIT_FAILURE 0 +#define EXIT_SUCCESS 0 +#define EXIT_FAILURE 1 void getNumInput(int* num); template void printSum(const T& n1, const T& n2);