diff --git a/cv3/program.c b/cv3/program.c index de4c827..8ec3532 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -29,6 +30,12 @@ int main(){ while(1){ ptr = fgets(char_value, STACK_SIZE-1, stdin); if(ptr != NULL ){ + if(char_value[0] == '0'){ + push_stack(&myStack,0); + print_stack(&myStack); + printf("\n"); + continue; + } float_value = strtof(char_value, NULL); if(float_value == 0){ if(char_value[0] == '+'){ @@ -57,6 +64,10 @@ int main(){ } if(char_value[0] == '/'){ float a = pop_stack(&myStack); + if(a == 0){ + printf("division by zero\n"); + break; + } float b = pop_stack(&myStack); float c = b/a; push_stack(&myStack, c); @@ -65,6 +76,7 @@ int main(){ } }else { + push_stack(&myStack, float_value); print_stack(&myStack); printf("\n");