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