I used Visual Studio's automatic formatting [Edit -> Advanced -> Format Selection (in 2010, I think 2012 lets you format the entire document)] to indent your code properly, and the problem becomes clear as day. Your braces don't balance where you think they do, and your indentation is making your problem harder to see. (Missing a closing brace at line 21)
#include<iostream>
#include<stdlib.h>
usingnamespace std;
constint stackSize = 5;
int stack[stackSize];
int top;
void push (int x)
{
if ( top == stackSize )
{
cout << "Unsuccessful push (" << x << ")\n";
}
else
{
stack[top] = x ;
++top ;
cout << "Successful push (" << x << ")\n";
}
void pop()
{
if ( top > 0 )
{
cout<<"pop is successful"<<endl;
--top;
}
else
{
cout<< "pop is unsuccessful, stack is underflowed"<<endl;
}
}
void display()
{
if (top<0)
{
cout<<"stack is empty"<<endl;
}
else
{
for (int i = top; i>0;i--)
cout<<stack[i]<<" "<<endl;
}
}
int main()
{
while(1)
{
int choice ;
cout<<" Welcome to the stack implemention"<<endl;
cout<< "Please look at the following options"<<endl;
cout<<" key in the corresponding number to sleect that option"<<endl;
cout<<" 1. PUSH 2. POP 3. DISPLAY 4. Exit\n"<<endl;
cout<<" Please enter your choice\n"<<endl;
cin>>choice;
switch(choice)
{
case 1:
{
int num ;
cout << "Enter a number\n" ;
cin >> num ;
push(num) ;
break ;
}
case 2: cout<<"you have popped an element out!"<<endl;
pop();
break;
case 3: display();
break ;
case 4: break;
}
}
}