I am doing a simple program that will add elements to a static stack using structures but Iam failing to implement it. The proram accepts input the first time but then crashes after that. Here is my structure declaration
struct stack{
int top=1;
int values[4];
};
the definition for the push function
void push(stack& s, int x)
{
cout<<"enter: ";
cin>>x;
cout<<endl;
s.top=s.top+1;
s.values[s.top]=x;
}
then i call it in main
int main(stack& s, int x)
{
push(s,x);
return 0;
}
Thanks for any help