From 45af434370b18379ac936ca789772a66ba46ed27 Mon Sep 17 00:00:00 2001 From: "Anthony C." Date: Mon, 31 Aug 2026 11:36:31 -0700 Subject: [PATCH] fixed Nan error --- main.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/main.cpp b/main.cpp index 5411e7a3..727ad27a 100644 --- a/main.cpp +++ b/main.cpp @@ -1,25 +1,29 @@ -#include #include +#include -using std::endl; using std::cin; using std::cout; +using std::endl; + +int main() { + cout << "THE FIRST EXAMPLE MATH DISPLAY!\n"; + cout << "Hi, please enter two whole numbers: "; -int main() -{ - cout << "THE FIRST EXAMPLE MATH DISPLAY!\n"; - cout << "Hi, please enter two whole numbers: "; + int x, y; - int x,y; + cin >> x >> y; - cin >> x >> y; - cout << "Addition: " << x + y << endl; - cout << "Subtraction: " << x - y << endl; - cout << "Multiplication: " << x * y << endl; + cout << "Addition: " << x + y << endl; + cout << "Subtraction: " << x - y << endl; + cout << "Multiplication: " << x * y << endl; + if (y == 0) { + cout << "Dividing by zero is not a number." << 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; }