diff --git a/du3/output/program.exe b/du3/output/program.exe index cead150..e145c0d 100644 Binary files a/du3/output/program.exe and b/du3/output/program.exe differ diff --git a/du3/program.c b/du3/program.c index d21a7c5..bbe5786 100644 --- a/du3/program.c +++ b/du3/program.c @@ -57,12 +57,47 @@ void destroy_stack (struct stack* s) { } int main() { - struct stack* novystack = create_stack(STACK_SIZE); - push_stack(novystack, 3.14); - push_stack(novystack, 2.71); - float x = pop_stack(novystack); - printf("Popped: %2.f\n", x); - print_stack(novystack); - destroy_stack(novystack); + struct stack* s = create_stack(STACK_SIZE); + char input[101]; + while (scanf("%s", input)==1) { + char *end; + float value = strtof(input, &end); + if (*end == '\0') { + push_stack(s, value); + print_stack(s); + } else if (strcmp(input, "+")==0 || strcmp(input, "-")==0 || strcmp(input, "*")==0 || strcmp(input, "/")==0) { + if (s->size < 2) { + printf("no input\n"); + destroy_stack(s); + return 0; + } + + float b = pop_stack(s); + float a = pop_stack(s); + float result = 0; + + if (strcmp(input, "+")==0) { + result = a+b; + } + if (strcmp(input, "-")==0) { + result = a - b; + } + if (strcmp(input, "*")==0) { + result = a * b; + } + if (strcmp(input, "/")==0) { + result = a/b; + } + push_stack(s); + print_stack(s); + } + else { + printf("no input"); + destroy_stack(s); + return 0; + } + } + destroy_stack(s); return 0; + } \ No newline at end of file