diff --git a/cv3/program.c b/cv3/program.c index 48054af..5ab87e8 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -25,7 +25,7 @@ int isFull(StEk* stek) { void push(StEk* stek, double chislo) { if (isFull(stek)) { - printf("no input\n"); + printf("not enough operands\n"); exit(1); } stek->chisla[stek->vershina] = chislo; @@ -34,7 +34,7 @@ void push(StEk* stek, double chislo) { double pop(StEk* stek) { if (isEmpty(stek)) { - printf("no input\n"); + printf("not enough operands\n"); exit(1); } return stek->chisla[--stek->vershina]; @@ -46,12 +46,15 @@ int main() { char bufer[256]; while (fgets(bufer, sizeof(bufer), stdin) != NULL) { if (bufer[0] == '\n') { - printf("no input\n"); + if (isEmpty(&stek)) { + printf("no input\n"); + } else { + double result = pop(&stek); + printf("%.2lf\n", result); + } return 0; } - - char* konec; double chislo = strtod(bufer, &konec); char c = konec[0]; @@ -60,13 +63,13 @@ int main() { push(&stek, chislo); } else if (c == '+' || c == '-' || c == '*' || c == '/') { if (isEmpty(&stek)) { - printf("no input\n"); - exit(1); + printf("not enough operands\n"); + return 0; } double b = pop(&stek); if (isEmpty(&stek)) { - printf("no input\n"); - exit(1); + printf("not enough operands\n"); + return 0; } double a = pop(&stek); if (c == '+') { @@ -85,7 +88,7 @@ int main() { } else if (!isdigit(c) || !isalpha(c)) { printf("bad input\n"); return 0; - } else{ + } else { printf("no input\n"); return 0; }