menu - options Problems

This is a discussion on menu - options Problems within the C Programming forums, part of the General Programming Boards category; hello.. I'm having a problem: Fisrt of all, i'm doing a program using graphics libraries of Borland. In my program, ...

  1. #1
    ~Team work is the best!~ wakish's Avatar
    Join Date
    Sep 2005
    Posts
    85

    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?
    # If you want to be happy, think of others.
    # If you want to be miserable, think of yourself

    ~~~Team work is the best!~~~

  2. #2
    Registered User
    Join Date
    Jun 2006
    Posts
    14
    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

  3. #3
    ~Team work is the best!~ wakish's Avatar
    Join Date
    Sep 2005
    Posts
    85
    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?
    # If you want to be happy, think of others.
    # If you want to be miserable, think of yourself

    ~~~Team work is the best!~~~

  4. #4
    Registered User
    Join Date
    Jun 2006
    Posts
    14
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Creating a menu that reads input via an array?
    By Nalif in forum C Programming
    Replies: 6
    Last Post: 09-29-2006, 09:21 PM
  3. Problems with a menu
    By L_U_K_E in forum C++ Programming
    Replies: 27
    Last Post: 04-28-2006, 10:45 AM
  4. Problems with my menu
    By Olidivera in forum Windows Programming
    Replies: 2
    Last Post: 07-07-2005, 12:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21