This commit is contained in:
Deinerovych 2024-10-16 10:12:58 +02:00
parent 69f29b231d
commit 6d18b78144

View File

@ -60,6 +60,7 @@ int main() {
char arr[50]; char arr[50];
char *pend; char *pend;
stack_top = -1; stack_top = -1;
bool first_output = true;
while (fgets(arr, 50, stdin)) { while (fgets(arr, 50, stdin)) {
if (arr[0] == '\n' || arr[0] == EOF) { if (arr[0] == '\n' || arr[0] == EOF) {
@ -69,11 +70,19 @@ int main() {
if (is_number(arr)) { if (is_number(arr)) {
float number = strtof(arr, &pend); float number = strtof(arr, &pend);
push(number); push(number);
printf("%.2f\n", number); if (!first_output) {
printf(" ");
}
printf("%.2f", number);
first_output = false;
} }
else if (is_operation(arr)) { else if (is_operation(arr)) {
if (stack_top < 1) { if (stack_top < 1) {
printf("no input\n"); if (!first_output) {
printf(" ");
}
printf("no input");
first_output = false;
continue; continue;
} }
@ -82,20 +91,35 @@ int main() {
char operation = arr[0]; char operation = arr[0];
float result = calculator(n1, n2, operation); float result = calculator(n1, n2, operation);
push(result); push(result);
printf("%.2f\n", result); if (!first_output) {
printf(" ");
}
printf("%.2f", result);
first_output = false;
} }
else { else {
printf("no input\n"); if (!first_output) {
printf(" ");
}
printf("no input");
first_output = false;
continue; continue;
} }
} }
if (stack_top == 0) { if (stack_top == 0) {
printf("%.2f\n", pop()); if (!first_output) {
printf(" ");
}
printf("%.2f", pop());
} else { } else {
printf("no input\n"); if (!first_output) {
printf(" ");
}
printf("no input");
} }
printf("\n");
return 0; return 0;
} }