Added division by 0 error checking

This commit is contained in:
2026-04-02 01:04:41 +03:00
parent f651fcdb4c
commit 000629b937
+12
View File
@@ -1,4 +1,5 @@
#include "basecalc.h" #include "basecalc.h"
#include <iostream>
BaseCalculator::~BaseCalculator() BaseCalculator::~BaseCalculator()
{} {}
@@ -20,10 +21,21 @@ int BaseCalculator::calculate(const Operation& op)
break; break;
case OpType::Division: case OpType::Division:
if (op.b == 0)
{
std::cerr << "Invalid operation requested! Resetting the accumulator to 0";
result = 0;
}
else
result = op.a / op.b; result = op.a / op.b;
break; break;
case OpType::Modulo: case OpType::Modulo:
if (op.b == 0)
{
std::cerr << "Invalid operation requested! Resetting the accumulator to 0";
result = 0;
}
result = op.a % op.b; result = op.a % op.b;
break; break;