Thread: menu problem!!! need U R G E N T help!!!

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    5

    Unhappy menu problem!!! need U R G E N T help!!!

    i want to make a menu and i am almost finished typing it. but i don't know how to return to the main menu again after an option is chosen.

    my program:

    Code:
    #include <stdio.h>
    
    void main_menu( );
    
     int main( )
    {
      
    
    main_menu();
    
      return 0;
    
    } 
    
    
    
    
    void main_menu()
    { int selection;
      
      printf( "*** ***** ***** ***** ***** ***** ***** ***\n" );  
      printf( "** * *** * *** * *** * *** * *** * *** * **\n" );  
      printf( "* *** * *** * *** * *** * *** * *** * *** *\n" );  
      printf( " ***** ***** ***** ***** ***** ***** ***** \n" );
      printf( "****          Welcome to MY PROGRM!       ****\n" );
      printf( " ***** ***** ***** ***** ***** ***** ***** \n" );
      printf( "* *** * *** * *** * *** * *** * *** * *** *\n" );
      printf( "** * *** * *** * *** * *** * *** * *** * **\n" );
      printf( "*** ***** ***** ***** ***** ***** ***** ***\n\n" );
              
      printf(" What is you name?");
      scanf("&#37;s");
      
                   
             printf("\nPlease choose one of the options below and enter its number: \n\n");
             printf(" 1) Count the total number of words\n");
             printf(" 2) Count the total number of vowels\n");
             printf(" 3) Count the total number of capital letters\n");
             printf(" 4) Reverse the text inputted\n");
             printf(" 5) Capitalize the first letters and lowercase other letters\n");
             printf(" 6) Exit\n\n");
    
      printf("Choose an option: ");
      scanf("%d", &selection);
     
      switch(selection){
        case 1:
          {
    
           /*function 1*/
          
    }
          break;
          
        case 2:
          {
    	
          /*function 2*/
    
    	
    }
          break;
        case 3:
          {
    
           /*function 3*/
            
    }
    
          break;
        case 4:
          {
    	
           /*function 4*/
    	
    }
          break;
        case 5:
          {
     
           /*function 5*/
    	
    }
    
          break;
        case 6:
          {
           int ch;
           fflush(stdin);
    	do
    	{
    	   puts("\nAre you sure you want to quit ? (Y/N)\n");
    	   ch = getc(stdin);
    	   if (ch == 'y')
    	{
    	    printf("\nThank you for using ! Byebye!\n");
    	    exit(0);
    	}
    	    else if (ch == 'n')
    	{
    	    puts("\nReturning to main menu...\n\n");
             
                main_menu();
    
                return ;
    	
    	}
    	}while(ch != 'n' || ch != 'y');
    	break;
    }
          break;
          default: 
          printf("\nInvalid selection! Program will end automatically.\n");
          break;
          
      }
    
    }
    i want to know how i can return to the main menu again without showing the following text
    Code:
     printf( "*** ***** ***** ***** ***** ***** ***** ***\n" );  
      printf( "** * *** * *** * *** * *** * *** * *** * **\n" );  
      printf( "* *** * *** * *** * *** * *** * *** * *** *\n" );  
      printf( " ***** ***** ***** ***** ***** ***** ***** \n" );
      printf( "****          Welcome to MY PROGRM!       ****\n" );
      printf( " ***** ***** ***** ***** ***** ***** ***** \n" );
      printf( "* *** * *** * *** * *** * *** * *** * *** *\n" );
      printf( "** * *** * *** * *** * *** * *** * *** * **\n" );
      printf( "*** ***** ***** ***** ***** ***** ***** ***\n\n" );
              
      printf(" What is you name?");
    but directly show the following part to the user.
    Code:
     printf("\nPlease choose one of the options below and enter its number: \n\n");
             printf(" 1) Count the total number of words\n");
             printf(" 2) Count the total number of vowels\n");
             printf(" 3) Count the total number of capital letters\n");
             printf(" 4) Reverse the text inputted\n");
             printf(" 5) Capitalize the first letters and lowercase other letters\n");
             printf(" 6) Exit\n\n");
    
      printf("Choose an option: ");
    Someone please help! i tried so many times but i still fail! =(
    please give me some examples!
    Last edited by catcat28; 11-19-2007 at 07:43 AM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You need a loop of some sort. A while, for or do-while loop.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > scanf("&#37;s");
    Where does the answer go here?
    Which compiler are you using? If it's a gcc port, then add "-Wall" to your command line options.

    > fflush(stdin);
    Another see the FAQ question. This is undefined.

    Perhaps adding two more functions would help.
    banner(), which prints that starry mass at the top of the page
    options(), which prints all the individual choices which are possible.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    5
    I use Miracle C.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Well there's your problem!
    Miracle C is a PoS.

    Anything on this list should help you enormously.
    http://www.cprogramming.com/compilers.html
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Nov 2007
    Posts
    5
    so wt can i do if i can only use miracle c? wt amendment i can make?

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by catcat28 View Post
    so wt can i do if i can only use miracle c? wt amendment i can make?
    You can add a loop of the appropriate kind to your code.

    Whilst the compiler may not be the best [I have never used it - so I can't say whether it's completely useless or just somewhat less than ideal], you certainly shoule be able to compile and run a simple project in it - and you're not saying "the code I've written can't be compiled", but "I don't know how to do this", and you have been given a few things that you can do to improve your code.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Well then you're sunk if you're stuck with that compiler, because it will fail miserably to compile even some basic programs which are correct, no matter what you do.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    I know this is a highly disliked way of doing it, but you can use a goto statement in the worst case.

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, don't do that when a loop or recursion can easily be applied (recursion does not apply here, though). A loop is the best alternative.

  11. #11
    lfs addicted
    Join Date
    Nov 2007
    Posts
    49
    Quote Originally Posted by Salem View Post
    Well there's your problem!
    Miracle C is a PoS.

    Anything on this list should help you enormously.
    http://www.cprogramming.com/compilers.html
    what "PoS" is standing for? I am ignorant

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Piece of scrap?

  13. #13
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    I think that last word may be a little different, depending on Salem's mood.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I think it should describe what the abbrevation meant fair enough, though.

  15. #15
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Yeah, not to mention keep your post from being deleted...
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. Simple Menu Problem
    By DanC in forum C++ Programming
    Replies: 4
    Last Post: 03-15-2006, 01:33 PM
  3. Problem with Mouse Over Menu!!! HELP!!!
    By SweeLeen in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2006, 02:10 AM
  4. Window - Menu problem...
    By FromHolland in forum Windows Programming
    Replies: 1
    Last Post: 02-26-2004, 03:49 PM
  5. MDI and MENU Problem
    By Marc in forum Windows Programming
    Replies: 3
    Last Post: 02-21-2004, 06:59 PM