I am making a program about stack, but everytime I enter a case choice, it loops the number i entered. Why so?
example : Enter your choice: 1 1 1 1 1 1 1 1 1 1- it doesnt stop asking
void display();
void push();
void pop();
void stackList();
int stack[100];
int top = -1;
int main(){
char ch;
char character; *// user input of char*
display ();
printf("\n\nEnter your choice: ");
do
{
scanf("%c",&ch); *// enter choice of user*
switch(ch)
{
case 1: push(); break;
case 2: pop(); break;
case 3: stackList(); break; *// display stacks*
}
}
while( ch != 'z' || ch != 'Z');
}
this is my push function
void push ()
{
char character;
printf("\n\npress 'Z' to exit.......");
if ( top == MAX -1 )
{
printf(" OVERFLOW ");
}
else
{
printf("Enter a character to push:\n");
do
{
scanf("%c",&character); *// asking user for character*
top = top+1;
stack[top]=character;
}
while( character != 'z' || character != 'Z');
printf("\nExiting...");
}
}
** for example : Enter your choice: 1 1 1 1 1 1 1 1 1 1- it doesnt stop asking **