ex01: fix: maybe useless

This commit is contained in:
starnakin 2023-12-16 12:22:02 +01:00
parent 481de18bbd
commit eb1819276f

View File

@ -13,7 +13,7 @@ int multiplication(int a, int b) { return (a * b); }
int calculate(std::stack<int>& nums, std::stack<char>& operators) int calculate(std::stack<int>& nums, std::stack<char>& operators)
{ {
if (nums.size() < 2 || operators.size() == 0) if (nums.size() < 2 || operators.size() == 0)
return 0; return 2;
int ret; int ret;
int b = nums.top(); int b = nums.top();
@ -62,11 +62,14 @@ int main(int ac, char** av)
else if (std::strchr("/+-*", av[1][i]) != NULL) else if (std::strchr("/+-*", av[1][i]) != NULL)
{ {
operators.push(av[1][i]); operators.push(av[1][i]);
if (calculate(nums, operators)) int ret = calculate(nums, operators);
if (ret == 1)
{ {
std::cout << "error: division by 0" << std::endl; std::cout << "error: division by 0" << std::endl;
return 1; return 1;
} }
else if (ret == 2)
break;
} }
else else
{ {