From 60e349509925c26f3e811303e5a1d8b66736b44b Mon Sep 17 00:00:00 2001 From: Yurii Yakovenko Date: Mon, 14 Oct 2024 19:58:34 +0000 Subject: [PATCH] Update cv3/program.c --- cv3/program.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index 785b6f8..4e6097e 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -1,7 +1,7 @@ #include #include #include -////////@@@@@@@@@@@ + #define STACK_SIZE 500 struct Stack @@ -48,7 +48,7 @@ int main() struct Stack mystack; mystack.size=0; //memset(&mystack,0,sizeof(struct Stack)); - + int err=0; char buf[505]; @@ -73,7 +73,15 @@ int main() { case '+': rez=op1+op2; break; case '-': rez=op1-op2; break; - case '/': rez=op1/op2; break; + case '/': + if(c=='/' && op2==0) + { + err=1; + printf("division_by_zero\n"); + } + else + rez=op1/op2; + break; case '*': rez=op1*op2; break; } //p } @@ -81,15 +89,17 @@ int main() { rez=atof(buf); } - push_stack(&mystack, rez); - //printf(" %.2f\n", rez); - print_stack(&mystack); + + if(!err) + { + push_stack(&mystack, rez); + //printf(" %.2f\n", rez); + print_stack(&mystack); + } } }while(1); - -printf("no input\n"); - - + if(!err) + printf("no input\n"); return 0; -} +} \ No newline at end of file