From ca26a0dc767ecb3f74b0157f466f1ea59fdc2d2d Mon Sep 17 00:00:00 2001 From: OneZeroCode Date: Mon, 15 Sep 2025 10:43:58 -0700 Subject: [PATCH] Handle divide-by-zero --- main.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index a495fc9..e182db1 100644 --- a/main.cpp +++ b/main.cpp @@ -1,21 +1,26 @@ #include #include -int main() -{ +int main() { std::cout << "THE FIRST EXAMPLE MATH DISPLAY!\n"; std::cout << "Hi, please enter two whole numbers: "; - int x,y; - + int x, y; std::cin >> x >> y; + 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 << "Division: " << x / y << std::endl; + } else { + std::cout << "Dividing by zero is not a number" << 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; + std::cout << "Square Root: " << std::sqrt(x) << std::endl; + std::cout << "Square: " << std::pow(x, y) << std::endl; return 0; }