From 000629b937b67c18a3292998145ec9abd389f62b Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 2 Apr 2026 01:04:41 +0300 Subject: [PATCH] Added division by 0 error checking --- basecalc.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/basecalc.cpp b/basecalc.cpp index fe8eb32..b16bed0 100644 --- a/basecalc.cpp +++ b/basecalc.cpp @@ -1,4 +1,5 @@ #include "basecalc.h" +#include BaseCalculator::~BaseCalculator() {} @@ -20,10 +21,21 @@ int BaseCalculator::calculate(const Operation& op) break; case OpType::Division: - result = op.a / op.b; + if (op.b == 0) + { + std::cerr << "Invalid operation requested! Resetting the accumulator to 0"; + result = 0; + } + else + result = op.a / op.b; break; case OpType::Modulo: + if (op.b == 0) + { + std::cerr << "Invalid operation requested! Resetting the accumulator to 0"; + result = 0; + } result = op.a % op.b; break;