From 47c08eb3f4305b4ac8a58d20ab034762343cc33e Mon Sep 17 00:00:00 2001 From: connorduncan Date: Mon, 2 Feb 2026 13:13:01 -0800 Subject: [PATCH] Prevents Divide By Zero Error Resolving Issue#61 --- main.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/main.cpp b/main.cpp index 5411e7a3..303bac64 100644 --- a/main.cpp +++ b/main.cpp @@ -7,19 +7,26 @@ 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; - cout << "Division: " << x / y << endl; - cout << "Remainder: " << x % y << endl; - cout << "Square Root: " << sqrt(x) << endl; - cout << "Square: " << pow(x, y) << endl; + cin >> x >> y; + cout << "Addition: " << x + y << endl; + cout << "Subtraction: " << x - y << endl; + cout << "Multiplication: " << x * y << endl; + if (x != 0) + { + cout << "Division: " << x / y << endl; + } + else + { + cout << "Dividing by zero is not a number." << endl; + } + cout << "Remainder: " << x % y << endl; + cout << "Square Root: " << sqrt(x) << endl; + cout << "Square: " << pow(x, y) << endl; - return 0; + return 0; }