From f8efe6e3862c0a5635d13c93209d78d55850e75b Mon Sep 17 00:00:00 2001 From: Denis Landa Date: Thu, 16 Oct 2025 17:25:01 +0000 Subject: [PATCH] Update du3/program.c --- du3/program.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/du3/program.c b/du3/program.c index 490e9fd..8a5a40d 100644 --- a/du3/program.c +++ b/du3/program.c @@ -18,7 +18,7 @@ void print_stack(struct stack *s) { void push_stack(struct stack *s, float value) { if (s->size >= STACK_SIZE) { - printf("full stack\n"); + printf("no input\n"); exit(0); } s->values[s->size] = value; @@ -27,7 +27,7 @@ void push_stack(struct stack *s, float value) { float pop_stack(struct stack *s) { if (s->size <= 0) { - printf("not enough operands\n"); + printf("no input\n"); exit(0); } s->size--; @@ -45,7 +45,7 @@ int main() { strcmp(input, "*") == 0 || strcmp(input, "/") == 0) { if (s.size < 2) { - printf("not anough operands\n"); + printf("no input\n"); exit(0); } @@ -53,6 +53,11 @@ int main() { float a = pop_stack(&s); float result; + if (strcmp(input, "/") == 0 && b == 0) { + printf("division by zero\n"); + exit(0); + } + if (strcmp(input, "+") == 0) result = a + b; else if (strcmp(input, "-") == 0) result = a - b; else if (strcmp(input, "*") == 0) result = a * b; @@ -65,14 +70,14 @@ int main() { char *endptr; float val = strtof(input, &endptr); if (*endptr != '\0') { - printf("division by zero\n"); + printf("no input\n"); exit(0); } push_stack(&s, val); print_stack(&s); } } - printf("no input\n"); + printf("no input\n"); return 0; }