debbug
This commit is contained in:
parent
1aff928a0d
commit
ca85e52bc2
@ -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");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user