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();
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.