Thread: Menu program

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    22

    Menu program

    Hey guys my teacher gave us comments in this program as to what to do in the program. I was pretty sure i filled out everything but low and behold when I try to run the program it doesnt work for some reason. Here is the code I have.

    Code:
    /* put your #define statements here */
     #include <stdio.h>
    
    /* put your prototypes here */
    void song(void);
    void show(void);
    int menu(void);
    int main(void)
    {
       /* declare your variable(s) here */
    
     char choice;
     
       choice = menu();   /* get user's first selection */
     
       while(choice != QUIT)
       {
          switch(choice)
          {
             case SHOW: show();
                         break;
             case SONG: song();
                         break;
             default:    printf("Oops! An invalid choice slipped through. ");
                         printf("Please try again.\n");
          }
          choice = menu(); /* get user's subsequent selections */
       }
     
       printf("Bye bye!\n");
     
       /* These next 3 lines are helpful if your program doesn't pause to let you
          see the output. (Not required.)
       */
       printf("Press Enter to end the program.\n");
       fflush(stdin);
       getchar();
     
       return 0;
    }
     
    int menu(void)
    {
       int option;
     
       /* Write printf() statements to make the following menu appear on the screen:
          
          Learn more about me! Please select from the menu.
     
          1. Learn the name of my favourite show.
          2. Learn the first line of my favourite song.
     
          0. Quit this program.
     
          Please enter your choice:
       */
        printf("1. Learn the name of my favourite show.\n");
        printf("2. Learn the first line of my favourite song.\n");
     
       while( (scanf(" %d", &option) != 1) /* non-numeric input */
              || (option < 0)               /* number too small */
              || (option > 2))              /* number too large */
       {
          fflush(stdin);                    /* clear bad data from buffer */
          printf("That selection isn't valid. Please try again.\n");
          printf("Your choice? ");
       }
       return option;
    }
     
    void song(void)
    {
       /* Write a printf() statement that will display 
          the first line of your favourite song. 
       */
    }
     
    void show(void)
    {
       /* Write a printf() statement that will display
          the title of your favourite TV (or stage) show.
       */

  2. #2
    Registered User
    Join Date
    Nov 2010
    Posts
    22
    dont worry about the printf statements for the song and the show i know those are missing i was going to put those in after.

  3. #3
    Registered User \007's Avatar
    Join Date
    Dec 2010
    Posts
    179
    Post the compiler errors...

    You didn't close the last function with a } bracket (maybe a pasting error..). I also don't see where QUIT is declared...

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    You have not defined QUIT, SHOW, SONG.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    22
    So defining Quit, show and song,

    This would be like

    #include <QUIT.h>
    #include <show.h>
    #include <song.h>

    Correct?

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by DerrickakaDRoC View Post
    So defining Quit, show and song,

    This would be like

    #include <QUIT.h>
    #include <show.h>
    #include <song.h>

    Correct?
    No. All caps is the standard convention for defined values:

    #define QUIT your value here
    #define SHOW your value here
    #define SONG your value here

    Note that there must NOT be a semi-colon at the end of a #define line, and no = (assignment) operator should be used.

    Defines work just like an editors search and replace function. This happens BEFORE the program is compiled, so it's a "dumb" replacement scheme.

    SHOW and show and Show, are all different things in C, so watch your case of letters.

    The way you SHOULD be doing this, is to get your overall program flow worked out the way you need it, and THEN get one other function working about right, and THEN get the next function working about right, etc.

    You don't want to be troubleshooting bugs in every funtion, all at the same time - it's overwhelming -- well not easy, at least. Take em on, one function at a time.
    Last edited by Adak; 12-10-2010 at 09:59 AM.

  7. #7
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    According to how your menu prompts the user, SHOW would be 1, SONG would be 2, QUIT would be 0.

  8. #8
    Registered User
    Join Date
    Nov 2010
    Posts
    22
    thanks guys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hi, Quiz C program Assignment updated
    By Eman in forum C Programming
    Replies: 19
    Last Post: 11-22-2009, 04:50 PM
  2. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM
  5. c++ program with a button menu
    By quakegod in forum C++ Programming
    Replies: 0
    Last Post: 01-07-2002, 01:09 AM