34
This commit is contained in:
parent
5bc9d6139c
commit
3be4df45de
@ -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,13 +52,12 @@ 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) {
|
||||
@ -65,7 +65,6 @@ void print_stack() {
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("no input\n");
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user