This commit is contained in:
Deinerovych 2024-10-16 22:38:56 +02:00
parent 5bc9d6139c
commit 3be4df45de

View File

@ -33,7 +33,7 @@ float calculator(float n1, float n2, char operation) {
return n1 / n2;
} else {
printf("division by zero\n");
return n1;
exit(0);
}
}
return 0;
@ -43,7 +43,8 @@ void push(float number) {
if (stack_top < STACK_SIZE - 1) {
stack[++stack_top] = number;
} else {
printf("stack overflow\n");
printf("Error: stack overflow\n");
exit(0);
}
}
@ -51,21 +52,19 @@ float pop() {
if (stack_top >= 0) {
return stack[stack_top--];
} else {
printf("stack is empty\n");
return 0;
printf("Error: stack is empty\n");
exit(0);
}
}
void print_stack() {
if (stack_top >= 0) {
for (int i = 0; i <= stack_top; i++) {
printf("%.2f", stack[i]);
if (i < stack_top) {
printf(" ");
}
for (int i = 0; i <= stack_top; i++) {
printf("%.2f", stack[i]);
if (i < stack_top) {
printf(" ");
}
printf(" \n");
}
printf(" \n");
}
int main() {
@ -93,13 +92,10 @@ int main() {
float n1 = pop();
char operation = arr[0];
float result = calculator(n1, n2, operation);
if (!(operation == '/' && n2 == 0)) {
push(result);
print_stack();
}
push(result);
print_stack();
}
}
printf("no input\n");
return 0;