From 5b9d8d433be39feb6e2c405b808f0622fb5e6ab5 Mon Sep 17 00:00:00 2001 From: Deinerovych Date: Wed, 16 Oct 2024 10:15:24 +0200 Subject: [PATCH] 6 --- cv3/program.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index 98f48e3..7b78371 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -61,6 +61,7 @@ int main() { char *pend; stack_top = -1; bool first_output = true; + bool operation_successful = true; while (fgets(arr, 50, stdin)) { if (arr[0] == '\n' || arr[0] == EOF) { @@ -75,6 +76,7 @@ int main() { } printf("%.2f", number); first_output = false; + operation_successful = true; } else if (is_operation(arr)) { if (stack_top < 1) { @@ -83,6 +85,7 @@ int main() { } printf("no input"); first_output = false; + operation_successful = false; continue; } @@ -96,6 +99,7 @@ int main() { } printf("%.2f", result); first_output = false; + operation_successful = true; } else { if (!first_output) { @@ -103,16 +107,17 @@ int main() { } printf("no input"); first_output = false; + operation_successful = false; continue; } } - if (stack_top == 0) { + if (operation_successful && stack_top == 0) { if (!first_output) { printf(" "); } printf("%.2f", pop()); - } else { + } else if (!operation_successful) { if (!first_output) { printf(" "); }