-
menu - options Problems
hello..
I'm having a problem:
Fisrt of all, i'm doing a program using graphics libraries of Borland.
In my program, i have several menus.
For example:
Code:
{.....
char option;
while(1)
{
option = getche();
display main menu
switch(option)
{
case 'a':
display sub-menu 1
case 'd':
display sub-menu 2
case 's':
//back to main menu
BREAK;
case 'w':
exit program
default: /*for any other key entered*/
continue;
}
}
}
My problem is this:
1) When i press any other keys, the menu is supposed to remain same. But after 4 key-strokes, every word on my menu becomes very small..that is the look of the menu changes.
I'm not being able to solve this so far.
Please can anyone try to help me out with this?
-
Not sure exactly what could be wrong..but I did use graphics along time back.
One way to improve the code, and hoepfully resolve your issue is putting the display main menu outside the loop and using getch() as follow:-
Code:
char option;
display main menu
while(1)
{
option = getch();
switch(option)
{
case 'a':
display sub-menu 1
case 'd':
display sub-menu 2
case 's':
display main menu
BREAK;
case 'w':
exit program
default: /*for any other key entered*/
continue;
}
}
This would avoid unnecessary refreshing of your main menu on invalid inputs, since you won't be doing anything. Not sure if would help though.
Edit: Corrected code alignment
-
no..if i put the "main menu" outside the loop, i won't be able to go back from a sub-menu..
that is, when i'm in a sub-menu and want to go back to main menu, the program will just exit..
But THANK YOU so much to have at least try to help me man..it's really appreciated!
Anyone else can help me, please?
-
Like I said before, Im suspecting the constant refreshing may be the one causing the problem you face, esp when you key in consecutive invalid entry. to overcome your later post, try these:-
Code:
display main menu
while(1)
{
option = getch();
switch(option)
{
case 'a':
display sub-menu 1
display main menu
case 'd':
display sub-menu 2
display main menu
case 's':
display main menu
BREAK;
case 'w':
exit program
default: /*for any other key entered*/
continue;
}
}
Since after exiting sub menu, you want the main menu back, you just call to reload it on the screen. Not very efficient when you look at it, but it does do away with the unnecessary refreshing and if that is what causing the problem, this might be the solution.
Another possibility is in you 'display main menu', some variables could be used incorrectly so after the fourth refresh, it just went bonkers with your display..you might wanna take a look at the 'display main menu' content again.