division by zero
This commit is contained in:
parent
d3c17b1c94
commit
deea72d872
@ -1,3 +1,4 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user