Hello programmers. I am learning how to make stacks. The instructor wants me to display the stack after you enter the elements or pop them out. All the examples I have seen so far from the book and the internet haven't shown me how to display them. So, not really sure how to do this. Here's the code I got so far from the header file.
What do you want to do?
1 - Push an item onto the stack
2 - Pop an item off the stack
3 - Quit the program
Enter your choice: 1
Enter an item: 1
11-842150451-842150451-842150451-842150451-842150451-842150451-842150451-8421504
51-842150451-842150451-842150451-842150451-842150451-842150451
What do you want to do?
1 - Push an item onto the stack
2 - Pop an item off the stack
3 - Quit the program
Enter your choice: 1
Enter an item: 2
212-842150451-842150451-842150451-842150451-842150451-842150451-842150451-842150
451-842150451-842150451-842150451-842150451-842150451
What do you want to do?
1 - Push an item onto the stack
2 - Pop an item off the stack
3 - Quit the program
Enter your choice: 1
Enter an item: 1
1121-842150451-842150451-842150451-842150451-842150451-842150451-842150451-84215
0451-842150451-842150451-842150451-842150451
What do you want to do?
1 - Push an item onto the stack
2 - Pop an item off the stack
3 - Quit the program
Enter your choice: 2
The stack is empty.
121-842150451-842150451-842150451-842150451-842150451-842150451-842150451-842150
451-842150451-842150451-842150451-842150451
What do you want to do?
1 - Push an item onto the stack
2 - Pop an item off the stack
3 - Quit the program
Enter your choice: 1
Enter an item: 3
3321-842150451-842150451-842150451-842150451-842150451-842150451-842150451-84215
0451-842150451-842150451-842150451-842150451
What do you want to do?
1 - Push an item onto the stack
2 - Pop an item off the stack
3 - Quit the program
Enter your choice: 3
Press any key to continue . . .
Oops. I don't think I wanted to put that there. What I had in mind was to display the stack but I am supposed to do that with printStack(). Taking that out.
top1 is the top of the stack.
The instructor specified that I need top() operation so it wouldn't let me to use "top" variable. So, instead, I put the 1 at the end so that way it doesn't act like it's trying to use the top() operation. Otherwise, I would get an error.
EDIT: Took "cout << item" out and still have the same results. Help!
I don't think I am properly coding the printStack() operation correctly. I think that is the source of the problem.
Good reply, but I asked about top1 because it's the key to the output problem. You are outputting all stackSize elements when only top1+1 elements should be displayed.