From 655faa97a3acde682618eb5e677481468ee3192c Mon Sep 17 00:00:00 2001 From: mycatdaphne <152930735+mycatdaphne@users.noreply.github.com> Date: Mon, 31 Aug 2026 11:43:20 -0700 Subject: [PATCH] fix: divide by zero problem, close #61 --- main.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 5411e7a3..ab7ee8e4 100644 --- a/main.cpp +++ b/main.cpp @@ -16,8 +16,12 @@ int main() cout << "Addition: " << x + y << endl; cout << "Subtraction: " << x - y << endl; cout << "Multiplication: " << x * y << endl; - cout << "Division: " << x / y << endl; - cout << "Remainder: " << x % y << endl; + if (y == 0) { + std::cerr << "Cannot divide by zero!\n"; + } else { + cout << "Division: " << x / y << endl; + cout << "Remainder: " << x % y << endl; + } cout << "Square Root: " << sqrt(x) << endl; cout << "Square: " << pow(x, y) << endl;