Thread: need help

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    14

    need help

    im writing a program that includes a menu,and has 2 options.i can write the program but when i enter and option,and complete it,how can i get the program to go back to the main menu??

  2. #2
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Put the code
    Code:
    return2menu();
    on line 47 of your second function.

    OR. . .

    Post your code so we can help you.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Pick better topic titles as well.
    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 2006
    Posts
    14
    sorry,this is my code:

    Code:
    #include <stdio.h>
    main()
    {
          int option ;
          
          
          printf( "Welcome to the main menu,please chose from the following options...:\n\n" ) ;//menu greating
          printf( "1.      opt1.\n\n" ) ;//option 1
          printf( "2.      op2.\n\n" ) ;//option 2
          
          
        
          
          
          printf( "Please chose an option between 1 - 2:\n") ;
          scanf( "%d",&option) ;//option input
          
          switch (option)       //begining of switch statement
          {
                
                
                
                case 1:
                     printf( "this is opt1\n") ; // begining of option 1
          
        
                
                
                
                
                case 2:
                     printf( "this is opt2" ) ;
                  break ;
                
                
                 }//end switch
          
          
          
          
          
          }//end main

  5. #5
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    Ever heard of a while loop??
    In the middle of difficulty, lies opportunity

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    14
    Quote Originally Posted by kris.c
    Ever heard of a while loop??
    yeh,but i cant really do them,im learning

  7. #7
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    we appreciate the fact that you atleast tried
    You can think of this :

    Code:
    #include <stdio.h>
    int main()
    {
          int option ,flag=0;
          
          
          printf( "Welcome to the main menu,please chose from the following options...:\n\n" ) ;//menu greating
          printf( "1.      opt1.\n\n" ) ;//option 1
          printf( "2.      op2.\n\n" ) ;//option 2
          printf(" 3.      exit  \n\n");
          
        
          while(flag == 0)
          {
          printf( "Please chose an option between 1 - 2:\n") ;
          scanf( "%d",&option) ;//option input
          
          switch (option)       //begining of switch statement
          {
                
                
                
                case 1:
                     printf( "this is opt1\n") ; // begining of option 1
          
        
                
               case 2:
                     printf( "this is opt2" ) ;
                  break ;
                
                
                 case 3:
                      printf(" exit");
                      flag=1;
                     break;           
    
               }//end switch
          
          } // end while
          
          
          return 0;
          }//end main
    In the middle of difficulty, lies opportunity

  8. #8
    Registered User
    Join Date
    Nov 2006
    Posts
    14
    thank you good sir!

  9. #9
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    wow! thats the best response I have ever got .
    and hey,I am just 20, so, dont bother about calling me that
    In the middle of difficulty, lies opportunity

  10. #10
    Registered User
    Join Date
    Nov 2006
    Posts
    14
    didnt work!!well it did,but its saying i display opt2 also!!

  11. #11
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    no sweat.. you have forgotten to insert a "break" statement after the "case 1."
    In the middle of difficulty, lies opportunity

  12. #12
    Registered User
    Join Date
    Nov 2006
    Posts
    14
    ah yes,thanks man

Popular pages Recent additions subscribe to a feed