From bb34fa76cd3844b6fcd312cd014b4bdcfa7ff5c7 Mon Sep 17 00:00:00 2001 From: Yevhen Kozirovskyi Date: Thu, 17 Oct 2024 17:52:48 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20cv3/program.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv3/program.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) 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; }