diff --git a/cv3/program.c b/cv3/program.c index 00adfe3..008266a 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -14,9 +14,9 @@ void print_stack(struct stack* s) { for (int i = 0; i < s->size; i++) { printf("%.2f", s->values[i]); if (i < s->size - 1) { - printf(" "); + printf(" "); } else { - printf(" "); + printf(" "); } } printf("\n"); @@ -25,7 +25,7 @@ void print_stack(struct stack* s) { void push_stack(struct stack* s, float value) { if (s->size >= STACK_SIZE) { printf("Chyba: zasobnik je plny\n"); - exit(0); + exit(1); } s->values[s->size++] = value; } @@ -33,7 +33,7 @@ void push_stack(struct stack* s, float value) { float pop_stack(struct stack* s) { if (s->size == 0) { printf("Chyba: zasobnik je prazdny\n"); - exit(0); + exit(1); } return s->values[--s->size]; } @@ -46,7 +46,7 @@ int is_operator(char* input) { void perform_operation(struct stack* s, char* operator) { if (s->size < 2) { printf("Chyba: nedostatok operandov\n"); - exit(0); + exit(1); } float b = pop_stack(s); @@ -62,12 +62,12 @@ void perform_operation(struct stack* s, char* operator) { } else if (strcmp(operator, "/") == 0) { if (b == 0) { printf("division by zero\n"); - exit(0); + exit(1); } result = a / b; } else { printf("Chyba: neplatna operacia\n"); - exit(0); + exit(1); } push_stack(s, result); @@ -84,15 +84,11 @@ int main() { float value; if (sscanf(input, "%f", &value) == 1) { push_stack(&mystack, value); - } - - else if (is_operator(input)) { + } else if (is_operator(input)) { perform_operation(&mystack, input); - } - - else { + } else { printf("bad input\n"); - return 0; + return 1; } print_stack(&mystack);