From d2b622ca558985bac861b8a4de64407618490be0 Mon Sep 17 00:00:00 2001 From: Giuseppe Pio Bacchi Date: Sat, 1 Nov 2025 08:51:37 +0100 Subject: [PATCH 1/9] Implementazione esercizio calculator --- exercises/calculator.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/exercises/calculator.cpp b/exercises/calculator.cpp index 013cc786..e8e42f87 100644 --- a/exercises/calculator.cpp +++ b/exercises/calculator.cpp @@ -10,3 +10,40 @@ Multiplication: 8 Division: 2 */ + + +#include +using namespace std; + +int main() { + double num1, num2; + + // Input dei numeri + cout << "Insert first number: "; + cin >> num1; + cout << "Insert second number: "; + cin >> num2; + + // Operazioni + double sum = num1 + num2; + double difference = num1 - num2; + double multiplication = num1 * num2; + double division; + + // Controllo divisione per zero + if(num2 != 0) { + division = num1 / num2; + } else { + cout << "Division by zero is not allowed." << endl; + } + + // Output + cout << "SUM: " << sum << endl; + cout << "Difference: " << difference << endl; + cout << "Multiplication: " << multiplication << endl; + if(num2 != 0) { + cout << "Division: " << division << endl; + } + + return 0; +} From 910fa8848f28686407162dedd5f9e9555dd869ea Mon Sep 17 00:00:00 2001 From: Giuseppe Pio Bacchi Date: Sun, 2 Nov 2025 11:06:34 +0100 Subject: [PATCH 2/9] Correzione esercizio calculator.cpp --- exercises/calculator.cpp | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/exercises/calculator.cpp b/exercises/calculator.cpp index e8e42f87..4154e326 100644 --- a/exercises/calculator.cpp +++ b/exercises/calculator.cpp @@ -13,37 +13,42 @@ #include +#include // per EXIT_FAILURE using namespace std; int main() { double num1, num2; - // Input dei numeri + // Input del primo numero cout << "Insert first number: "; - cin >> num1; - cout << "Insert second number: "; - cin >> num2; + if (!(cin >> num1)) { + cerr << "Invalid input." << endl; + return EXIT_FAILURE; + } + + // Input del secondo numero, controllo divisione per zero + while (true) { + cout << "Inserisci secondo numero: "; + if (!(cin >> num2)) { + cerr << "ERRORE" << endl; + return EXIT_FAILURE; + } + if (num2 != 0) break; // numero valido + cout << "Inserisci un'altro numero" << endl; + } // Operazioni double sum = num1 + num2; double difference = num1 - num2; double multiplication = num1 * num2; - double division; - - // Controllo divisione per zero - if(num2 != 0) { - division = num1 / num2; - } else { - cout << "Division by zero is not allowed." << endl; - } + double division = num1 / num2; // Output cout << "SUM: " << sum << endl; cout << "Difference: " << difference << endl; cout << "Multiplication: " << multiplication << endl; - if(num2 != 0) { - cout << "Division: " << division << endl; - } + cout << "Division: " << division << endl; return 0; } + From 4afc4020bbf05cfdc5c70b7d97ad692afe936b6b Mon Sep 17 00:00:00 2001 From: Giuseppe Pio Bacchi Date: Sun, 2 Nov 2025 18:13:40 +0100 Subject: [PATCH 3/9] Correzione esercizio calculator.cpp secondo i suggerimenti della PR --- exercises/calculator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/calculator.cpp b/exercises/calculator.cpp index 4154e326..78b6d959 100644 --- a/exercises/calculator.cpp +++ b/exercises/calculator.cpp @@ -49,6 +49,6 @@ int main() { cout << "Multiplication: " << multiplication << endl; cout << "Division: " << division << endl; - return 0; + return EXIT_SUCCESS; } From 51dc5864587c90f699d5fe9776dfb7285099686b Mon Sep 17 00:00:00 2001 From: Giuseppe Pio Bacchi Date: Sun, 2 Nov 2025 18:56:09 +0100 Subject: [PATCH 4/9] fix: restore original sum.cpp --- sum.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 sum.cpp diff --git a/sum.cpp b/sum.cpp new file mode 100644 index 00000000..0dcca937 --- /dev/null +++ b/sum.cpp @@ -0,0 +1,8 @@ +/* + Write a program that takes as input two numbers and print the sum. + + Output: + Insert the first number: 1 + Insert the second number: 2 + Sum: 3 +*/ From e9e50303b7d9062a3a11a04583aec5cc281be328 Mon Sep 17 00:00:00 2001 From: Giuseppe Pio Bacchi Date: Sun, 2 Nov 2025 19:30:40 +0100 Subject: [PATCH 5/9] chore: rimuove sum.cpp dal commit --- exercises/sum.cpp | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 exercises/sum.cpp diff --git a/exercises/sum.cpp b/exercises/sum.cpp deleted file mode 100644 index 0dcca937..00000000 --- a/exercises/sum.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* - Write a program that takes as input two numbers and print the sum. - - Output: - Insert the first number: 1 - Insert the second number: 2 - Sum: 3 -*/ From a2a35eb0b0032891bfadfa6b138163d1239f18ce Mon Sep 17 00:00:00 2001 From: Giuseppe Pio Bacchi Date: Sun, 2 Nov 2025 19:37:59 +0100 Subject: [PATCH 6/9] feat: init exercises --- exercises/sum.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 exercises/sum.cpp diff --git a/exercises/sum.cpp b/exercises/sum.cpp new file mode 100644 index 00000000..0dcca937 --- /dev/null +++ b/exercises/sum.cpp @@ -0,0 +1,8 @@ +/* + Write a program that takes as input two numbers and print the sum. + + Output: + Insert the first number: 1 + Insert the second number: 2 + Sum: 3 +*/ From 67b15f1951e367199199ac4b914f739ec80cf150 Mon Sep 17 00:00:00 2001 From: Giuseppe Pio Bacchi Date: Sun, 2 Nov 2025 19:42:37 +0100 Subject: [PATCH 7/9] chore: rimuove sum.cpp dal commit --- exercises/sum.cpp | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 exercises/sum.cpp diff --git a/exercises/sum.cpp b/exercises/sum.cpp deleted file mode 100644 index 0dcca937..00000000 --- a/exercises/sum.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* - Write a program that takes as input two numbers and print the sum. - - Output: - Insert the first number: 1 - Insert the second number: 2 - Sum: 3 -*/ From a7331cdb22d32a8f13b256f1beae40b3aeeefe28 Mon Sep 17 00:00:00 2001 From: Giuseppe Pio Bacchi Date: Sun, 2 Nov 2025 22:24:29 +0100 Subject: [PATCH 8/9] Rimuove sum.cpp dal repository --- sum.cpp | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 sum.cpp diff --git a/sum.cpp b/sum.cpp deleted file mode 100644 index 0dcca937..00000000 --- a/sum.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* - Write a program that takes as input two numbers and print the sum. - - Output: - Insert the first number: 1 - Insert the second number: 2 - Sum: 3 -*/ From cbfcaf419326956c68d8c3abe319914604320210 Mon Sep 17 00:00:00 2001 From: Giuseppe Pio Bacchi Date: Sun, 2 Nov 2025 22:28:14 +0100 Subject: [PATCH 9/9] feat: init exercises --- exercises/sum.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 exercises/sum.cpp diff --git a/exercises/sum.cpp b/exercises/sum.cpp new file mode 100644 index 00000000..0dcca937 --- /dev/null +++ b/exercises/sum.cpp @@ -0,0 +1,8 @@ +/* + Write a program that takes as input two numbers and print the sum. + + Output: + Insert the first number: 1 + Insert the second number: 2 + Sum: 3 +*/