Division by zero fix

This commit is contained in:
Anton Dolozin 2025-10-06 16:18:52 +02:00
parent e32968a164
commit 2ff0fd0ddf

View File

@ -47,10 +47,17 @@ void process_operations(struct stack* stack) {
if (stack->size >= 2) {
float b = pop_stack(stack);
float a = pop_stack(stack);
if (line[0] == '/' && b == 0.0F)
{
printf("division by zero\n");
return;
}
float res = (line[0] == '+') ? a + b :
(line[0] == '-') ? a - b :
(line[0] == '*') ? a * b :
(line[0] == '/') ? a / b : 0;
push_stack(stack, res);
print_stack(stack);
} else {