From f97550ca799282a0368c57bc669e9b4bac6a3a7d Mon Sep 17 00:00:00 2001 From: Kevin Buffardi Date: Wed, 28 Jan 2026 11:42:38 -0800 Subject: [PATCH 1/3] Prevents divide by zero, resolves #61 --- main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index a495fc94..0685c71b 100644 --- a/main.cpp +++ b/main.cpp @@ -12,7 +12,12 @@ int main() std::cout << "Addition: " << x + y << std::endl; std::cout << "Subtraction: " << x - y << std::endl; std::cout << "Multiplication: " << x * y << std::endl; - std::cout << "Division: " << x / y << std::endl; + if( y == 0 ){ + std::cout << "Dividing by zero is not a number.\n"; + } + else{ + std::cout << "Division: " << x / y << std::endl; + } std::cout << "Remainder: " << x % y << std::endl; std::cout << "Square Root: " << sqrt(x) << std::endl; std::cout << "Square: " << pow(x, y) << std::endl; From 39cd234c95b8ad99f95e1cdec07abfa4cc5d9a14 Mon Sep 17 00:00:00 2001 From: Skye Santilla Date: Mon, 2 Feb 2026 15:32:12 -0800 Subject: [PATCH 2/3] Handle divide-by-zero in division output --- main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.cpp b/main.cpp index 652ca31c..b8a2eeb3 100644 --- a/main.cpp +++ b/main.cpp @@ -16,7 +16,11 @@ int main() cout << "Addition: " << x + y << endl; cout << "Subtraction: " << x - y << endl; cout << "Multiplication: " << x * y << endl; + if( y == 0 ){ + + cout << "Division: " << x / y << endl; + if( y == 0 ){ cout << "Dividing by zero is not a number.\n"; } else{ From 42d3952a6d24611d6f2c5018791718dd90e09e37 Mon Sep 17 00:00:00 2001 From: Skye Santilla Date: Mon, 2 Feb 2026 15:50:56 -0800 Subject: [PATCH 3/3] Clean up divide-by-zero handling logic --- main.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index b8a2eeb3..bbebb952 100644 --- a/main.cpp +++ b/main.cpp @@ -17,15 +17,12 @@ int main() cout << "Subtraction: " << x - y << endl; cout << "Multiplication: " << x * y << endl; - if( y == 0 ){ - + if (y == 0) { + cout << "Dividing by zero is not a number." << endl; + } else { cout << "Division: " << x / y << endl; - if( y == 0 ){ - cout << "Dividing by zero is not a number.\n"; - } - else{ - cout << "Division: " << x / y << std::endl; } + cout << "Remainder: " << x % y << endl; cout << "Square Root: " << sqrt(x) << endl; cout << "Square: " << pow(x, y) << endl;