From 3752d7bff4c4167e430d3f313b67908fff20a0f3 Mon Sep 17 00:00:00 2001 From: EdJaPe Date: Wed, 28 Jan 2026 11:49:50 -0800 Subject: [PATCH 1/2] prevents divide by Zero, resolves #61 --- main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index a495fc94..de691bf9 100644 --- a/main.cpp +++ b/main.cpp @@ -12,7 +12,12 @@ int main() 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 << "Dividing by zero is not a number.\n"; + }else{ + + std::cout << "Division: " << x / y << 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; From 6ec8a7999204a514815217c859787a7e9ac79457 Mon Sep 17 00:00:00 2001 From: EdJaPe Date: Mon, 2 Feb 2026 12:42:34 -0800 Subject: [PATCH 2/2] refactored code --- main.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/main.cpp b/main.cpp index de691bf9..ed68043a 100644 --- a/main.cpp +++ b/main.cpp @@ -1,26 +1,32 @@ #include #include +using std::cin; +using std::endl; +using std::cout; + + + int main() { - std::cout << "THE FIRST EXAMPLE MATH DISPLAY!\n"; - std::cout << "Hi, please enter two whole numbers: "; + cout << "THE FIRST EXAMPLE MATH DISPLAY!\n"; + cout << "Hi, please enter two whole numbers: "; 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; + cin >> x >> y; + cout << "Addition: " << x + y << endl; + cout << "Subtraction: " << x - y << endl; + cout << "Multiplication: " << x * y << endl; if(y == 0) { - std::cout << "Dividing by zero is not a number.\n"; + cout << "Dividing by zero is not a number.\n"; }else{ - std::cout << "Division: " << x / y << std::endl; + cout << "Division: " << x / y << endl; } - std::cout << "Remainder: " << x % y << std::endl; - std::cout << "Square Root: " << sqrt(x) << std::endl; - std::cout << "Square: " << pow(x, y) << std::endl; + cout << "Remainder: " << x % y << endl; + cout << "Square Root: " << sqrt(x) << endl; + cout << "Square: " << pow(x, y) << endl; return 0; }