diff --git a/cv3/program.c b/cv3/program.c index 9379bef..9e4c138 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -26,10 +26,10 @@ void print_stack(struct stack *stack){ int i; int len = stack->size - 1; for(i = 0; i < len; i++){ - printf("%0.2g ", stack->values[i]); + printf("%0.2f ", stack->values[i]); } if(stack->size != 0){ - printf("%0.2g ", stack->values[i]); + printf("%0.2f ", stack->values[i]); } printf("\n"); @@ -40,6 +40,7 @@ int main() { struct stack mystack; memset(&mystack, 0, sizeof(struct stack)); int i = 0; + float z; for(i = 0; i < 10000; i++){ char line[10]; char *x = fgets(line, 10, stdin); @@ -53,13 +54,17 @@ int main() { r = pop(&mystack) + pop(&mystack); } else if(line[0] == '-'){ - r = pop(&mystack) - pop(&mystack); + z = pop(&mystack); + r = pop(&mystack) - z; } else if(line[0] == '*'){ r = pop(&mystack) * pop(&mystack); } else if(line[0] == '/'){ - r = pop(&mystack) / pop(&mystack); + z = pop(&mystack); + if(z != 0.0){ + r = pop(&mystack) / z; + } } else {