I have a switch/case statement using numerics for a menu, but when i enter an alphanumeric statment it goes into a loop printing my menu and the default statement from switch/case the default statement. The only way to end it is ctrl-c. the code is below. Can someone please explain this quirk to me?
[CODE=c]
#include<stdio. h>
#include<stdlib .h>
int CHOICE;
int LTENC[11];
//SNIPPED - cArrayModify(); / pLastTen();
void doNothing()
{
printf("\n");
cArrayModify();
}
void invalidChoice()
{
printf(" Invalid Choice!! \n");
cArrayModify();
}
void menu()
{
cArrayModify();
printf(" \n \n");
printf(" Menu: \n");
printf(" 1 - Print Menu \n");
printf(" 2 - Do nothing \n");
printf(" 3 - Exit \n \n");
pLastTen();
}
int programexit()
{
printf("\n Exit Conditions met, program will now exit!\n");
return 0;
}
void commandlp()
{
while(1)
{
printf("-> ");
scanf("%d",&CHO ICE);
switch(CHOICE)
{
case 1 : menu();
break;
case 2 : doNothing();
break;
case 3 : programexit();
exit(0);
default: invalidChoice() ;
break;
}
}
}
int main()
{
menu();
commandlp();
}[/CODE]
[CODE=c]
#include<stdio. h>
#include<stdlib .h>
int CHOICE;
int LTENC[11];
//SNIPPED - cArrayModify(); / pLastTen();
void doNothing()
{
printf("\n");
cArrayModify();
}
void invalidChoice()
{
printf(" Invalid Choice!! \n");
cArrayModify();
}
void menu()
{
cArrayModify();
printf(" \n \n");
printf(" Menu: \n");
printf(" 1 - Print Menu \n");
printf(" 2 - Do nothing \n");
printf(" 3 - Exit \n \n");
pLastTen();
}
int programexit()
{
printf("\n Exit Conditions met, program will now exit!\n");
return 0;
}
void commandlp()
{
while(1)
{
printf("-> ");
scanf("%d",&CHO ICE);
switch(CHOICE)
{
case 1 : menu();
break;
case 2 : doNothing();
break;
case 3 : programexit();
exit(0);
default: invalidChoice() ;
break;
}
}
}
int main()
{
menu();
commandlp();
}[/CODE]
Comment