From 6eb525c34d5a51fab4a6cd688775c8f2c4dcf3da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Korpesio?= Date: Wed, 20 Oct 2021 10:51:31 +0200 Subject: [PATCH] prvy --- cv3/program.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index ec25fd9..499e767 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -21,11 +21,11 @@ int main() { while (fgets(line, LINESIZE, stdin)) { velkost = strlen(line); if (velkost == 1 && line[velkost - 1] == '\n') { - printf("no input\n"); + break; } if (input >= 10){ - printf("no input\n"); + break; } if (line[0] == '+' || line[0] == '-' || line[0] == '*' || line[0] == '/') { @@ -43,9 +43,14 @@ int main() { a--; } if (line[0] == '/') { - number[a - 2].cislo = number[a - 2].cislo / number[a - 1].cislo; - a--; - } + if (number[a - 1].cislo == 0){ + printf("division by zero"); + } + else { + number[a - 2].cislo = number[a - 2].cislo / number[a - 1].cislo; + a--; + } + } } else { p = atof(line);