From ca85e52bc2fb598abe194b15e444666e62ba553e Mon Sep 17 00:00:00 2001 From: vj586da Date: Fri, 22 Oct 2021 01:21:30 +0200 Subject: [PATCH] debbug --- cv3/program.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index 187564a..da0a5b7 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -29,7 +29,7 @@ void substract(struct stack* stack); void multip(struct stack* stack); //function to divide last 2 operands from stack -void divis(struct stack* stack); +void divis(struct stack* stack, float a); int main(){ @@ -80,7 +80,13 @@ int main(){ //division else if(char_value[0] == '/'){ if(myStack.size > 1){ - divis(&myStack); + float a = pop_stack(&myStack); + if(a == 0){ + printf("division by zero\n"); + break; + }else{ + divis(&myStack, a); + } }else{puts("not enough operands"); break;} } @@ -155,16 +161,10 @@ void multip(struct stack* stack){ -void divis(struct stack* stack){ - float a = pop_stack(&myStack); - if(a == 0){ - printf("division by zero\n"); - break; - }else{ - float b = pop_stack(&myStack); +void divis(struct stack* stack, float a){ + float b = pop_stack(stack); float c = b/a; - push_stack(&myStack, c); - print_stack(&myStack); + push_stack(stack, c); + print_stack(stack); printf("\n"); - } }