diff --git a/cv3/program.c b/cv3/program.c index 35c47cc..1092d4c 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -34,10 +34,12 @@ float pop_stack(struct stack *s) { } void print_stack(struct stack *s) { - for (int i = 0; i < s->size; i++) { - printf("%.2f ", s->values[i]); + if (s->size > 0) { + for (int i = 0; i < s->size; i++) { + printf("%.2f ", s->values[i]); + } + printf("\n"); } - printf("\n"); } int read(struct stack *s) { @@ -76,7 +78,7 @@ int read(struct stack *s) { // Check for sufficient values in the stack if (s->size < 2) { printf("no input\n"); - exit(1); // Exit if not enough values + return 1; // Don't exit; continue to next iteration } float b = pop_stack(s); // Pop the last two values @@ -96,8 +98,9 @@ int read(struct stack *s) { break; } push_stack(s, result); // Push the result back onto the stack - // Print the result print_stack(s); // Print the stack after operation + printf("no input\n"); // Print the "no input" message + exit(0); // Exit the program after the operation break; } default: