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(" "); }