Update cv3/program.c
This commit is contained in:
parent
fdd5e20544
commit
23b008887d
@ -34,10 +34,12 @@ float pop_stack(struct stack *s) {
|
||||
}
|
||||
|
||||
void print_stack(struct stack *s) {
|
||||
if (s->size > 0) {
|
||||
for (int i = 0; i < s->size; i++) {
|
||||
printf("%.2f ", s->values[i]);
|
||||
}
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user