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);