not enough operands

This commit is contained in:
Valér Jakubčo 2021-10-22 00:30:38 +02:00
parent 1b5225eb40
commit ec7edc0f3c

View File

@ -17,7 +17,6 @@ void push_stack(struct stack* stack, float value);
float pop_stack(struct stack* stack);
int main(){
@ -43,27 +42,34 @@ int main(){
}*/
if(char_value[0] == '+'){
if(myStack.size > 1){
float a = pop_stack(&myStack);
float b = pop_stack(&myStack);
float c = a+b;
push_stack(&myStack, c);
print_stack(&myStack);
printf("\n");
}else{puts("not enough operands"); break;}
}else if(char_value[0] == '-'){
if(myStack.size > 1){
float a = pop_stack(&myStack);
float b = pop_stack(&myStack);
float c = b-a;
push_stack(&myStack, c);
print_stack(&myStack);
printf("\n");
}else{puts("not enough operands"); break;}
}else if(char_value[0] == '*'){
if(myStack.size > 1){
float a = pop_stack(&myStack);
float b = pop_stack(&myStack);
float c = a*b;
push_stack(&myStack, c);
print_stack(&myStack);
printf("\n");
}else{puts("not enough operands"); break;}
} else if(char_value[0] == '/'){
if(myStack.size > 1){
float a = pop_stack(&myStack);
if(a == 0){
printf("division by zero\n");
@ -75,6 +81,7 @@ int main(){
print_stack(&myStack);
printf("\n");
}
}else{puts("not enough operands"); break;}
} else if(isdigit(char_value[0]) != 0 ){
float_value = strtof(char_value, NULL);
//printf("float value: %f\n",float_value);
@ -122,3 +129,4 @@ float pop_stack(struct stack* stack){
stack->size -= 1;
return value;
}