Hi , I've been trying to write a program that will stack numbers in a row (while the number is less than 9). The pop function which I've written is supposed to remove all of the elements that are more than 9 and list them as being popped. The problem I am having now is that I want to be able to "peek" into the stack before the numbers are "popped" and after they are "popped".

I've written the "peek" function but am unable to get the correct answer. It only returns one number in the current stack instead of all of them (before pop).

Also i wanted to reverse the order of my push/pop so that the number greater then 9 is the one that gets popped but I'll figure that one out. Please let me know if you have any ideas because I am not receiving any error messages when I compile which would tell me what's wrong with the program.

Thanks

Special thanks to Elad and Shakti

Code:#include <iostream.h> const int Stack_Size=100; class Stack { public: Stack(); void push(int); int pop(); int peek(); bool empty(); bool full(); private: int count; int data[Stack_Size]; }; Stack::Stack() { count=-1; } void Stack::push(int value) { count++; data[count]=value; } int Stack::pop() { int topval; topval=data[count]; count--; return(topval); } int Stack::peek() { int elements; elements=data[count]; return (elements); } bool Stack::empty() { if (count==-1) return 1; else return 0; } bool Stack::full() { if (count==Stack_Size-1) return 1; else return 0; } int main() { Stack digits; int newnum; cout<<" Enter as many digits as you wish\n "; while(1) { cout<<"enter a digit\n"; cin>>newnum; if (newnum>9) break; if (digits.full()) { cout<<"The stack is full and you do not have any space left\n"; break; } else digits.push(newnum); } cout<<"The values that are currently in the stack (peek) are\n"<<digits.peek()<<endl; cout<<"The values that were popped from the stack are\n"; if (digits.empty()) { cout<<"The stack is empty\n"; } else while (!digits.empty()) { cout<<digits.pop()<<endl; } return 0; }