From 6d3a815e89632e57b547d5e484876fc705c9b848 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 31 Aug 2026 11:38:33 -0700 Subject: [PATCH] fix: divide by zero problem, close #61 --- main.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/main.cpp b/main.cpp index 5411e7a3..8c7e7fa8 100644 --- a/main.cpp +++ b/main.cpp @@ -7,19 +7,25 @@ using std::cout; int main() { - cout << "THE FIRST EXAMPLE MATH DISPLAY!\n"; - cout << "Hi, please enter two whole numbers: "; + cout << "THE FIRST EXAMPLE MATH DISPLAY!\n"; + cout << "Hi, please enter two whole numbers: "; - int x,y; + int x,y; - cin >> x >> y; - cout << "Addition: " << x + y << endl; - cout << "Subtraction: " << x - y << endl; - cout << "Multiplication: " << x * y << endl; + cin >> x >> y; + cout << "Addition: " << x + y << endl; + cout << "Subtraction: " << x - y << endl; + cout << "Multiplication: " << x * y << endl; + if (y == 0) + { + cout << "Division: Undefined" << endl; + cout << "Remainder: Undefined" << endl; + } else { cout << "Division: " << x / y << endl; cout << "Remainder: " << x % y << endl; - cout << "Square Root: " << sqrt(x) << endl; - cout << "Square: " << pow(x, y) << endl; + } + cout << "Square Root: " << sqrt(x) << endl; + cout << "Square: " << pow(x, y) << endl; - return 0; + return 0; }