my invalid key is runing like mad non stop...

my invalid key is running non stop how can i stop it
this is my following codes:


/*create user-define functions
this is a user define demo*/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

int CountOnRun(); //step2 function prototype
int CountOnSpot(); //step2 function prototype
int LetGo(); //step2 function prototype
int CleanUp(); //step2 function prototype
int IntroPage();
int SelectionMenu();
int exit();

int main()
{
char keynum;
IntroPage();
SelectionMenu();




printf("\n");
system("pause");
return 0;
}





int IntroPage()
{
system("cls"); // clear previous screen
printf("\tC Programming Miniproj Intropage\n");
printf("\t=================================\n");
printf("\tModule Group: A7\n");
printf("\tTasks & members:\n");
printf("\tCount On Run -- Tan Ek Kiang\n");
printf("\tCount On Spot -- Tan Ek Kiang\n");
printf("\tLet Go -- Tan Ek Kiang\n");
printf("\tClean Up -- Tan Ek Kiang\n");
printf("\tPress any key to continue . . .");
getch();

}



int SelectionMenu()
{
char keynum;

system("cls"); // clear previous screen
printf("\tSelection Menu\n");
printf("\t1. Count On run\n");
printf("\t2. Count On Spot\n");
printf("\t3. Let Go \n");
printf("\t4. Clean Up\n");
printf("\t5. Exit\n");
printf("\tEnter your selection here: ");
//scanf(" %d",&keynum);
keynum=getch();

do
{

if (keynum == '1')
{
CountOnRun();
}
else if(keynum == '2')
{
CountOnSpot();
}
else if (keynum =='3')
{
LetGo();
}
else if (keynum == '4')
{
CleanUp();
}
else if(keynum == '5')
{
//exit();
}
else
{
printf("\tInvalid Key");
}
}while (keynum!='5');


}

/*step 1: create the function */
int CountOnRun()
{
char character;
int num;
do
{
system("cls");// clear system screen

printf("\tCount On Run Operation\n");
printf("\t======================\n\n");
printf("\t");

for(num=0 ; num<21 ; num++)
{
printf("%02d \a",num);
_sleep(500);
}

printf("\n\n");
printf("\tTry Again?");

character = getch();
}
while (( character == 'y') || ( character == 'Y'));// character must be only y or Y
return SelectionMenu();
}

int CountOnSpot()
{
char character;
int num;
do
{
system("cls");// clear system screen

printf("\tCount On Spot Operation\n");
printf("\t======================\n\n");

for(num=0 ; num<21 ; num++)
{
printf("\t%02d \a\r",num);
_sleep(500);
}

printf("\n\n");
printf("\tTry Again?");

character = getch();
}
while (( character == 'y') || ( character == 'Y'));// character must be only y or Y
return SelectionMenu();
}

int LetGo()
{
char character;
int num;
do
{
system("cls");// clear system screen

printf("\tClean Up Operation\n");
printf("\t======================\n\n");
printf("\t@ * @ * @ * @ * @ * @ * @ * @ * @ * @ * ");

for(num=0 ; num<38 ; num++)
{

printf("\b\b\b_\a");
_sleep(200);
printf(" ");
_sleep(200);


}

printf("\n\n");
printf("\tTry Again?");

character = getch();
}
while (( character == 'y') || ( character == 'Y'));// character must be only y or Y
return SelectionMenu();
}

int CleanUp()
{
char character;
int num;
do
{
system("cls");// clear system screen

printf("\tClean Up Operation\n");
printf("\t======================\n\n");
printf("\t@ * @ * @ * @ * @ * @ * @ * @ * @ * @ * ");

for(num=0 ; num<38 ; num++)
{

printf("\b\b\b_\a");
_sleep(200);
printf(" ");
_sleep(200);


}

printf("\n\n");
printf("\tTry Again?");

character = getch();
}
while (( character == 'y') || ( character == 'Y'));// character must be only y or Y
return SelectionMenu();
}
/*int exit()
{
system("cls");// clear system screen
printf("\tThank you for using this program,\n");
_sleep(500);
printf("\tHave a nice day.\n");
_sleep(500);
return 0;
}*/

Agh, please use [code][/code] tags in the future. In any case, it seems like if you put in any invalid key, it will continue doing the while loop without asking for input again; the kill will always be invalid.

Just a comment, but your program structure seems very odd; ignoring system() and such, they way you have each function use a recursive tail-call to go back to the main menu makes it hard to follow...at least for me.
Topic archived. No new replies allowed.