Thread: Help me complete this code please.

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

    Help me complete this code please.

    A menu-driven program.

    The goal of this program is to become familiar with the structure of a program that uses a menu. I will give you the outline; you fill in the details.

    Code:
     
    #include <stdio.h>
    /* put your #define statements here */
    /* put your prototypes here */
     
    int main(void)
    {
       /* declare your variable(s) here */
     
       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:
       */
     
       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
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    No - you fill in your own tutor boilerplate code first.
    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.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    BAD tutor boilerplate at that! fflush(stdin)! BARF!!!

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    I will give you the outline; you fill in the details
    The mind boggles
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  5. #5
    Registered User l2krence's Avatar
    Join Date
    Nov 2010
    Posts
    24
    lol, is this an exercise ? O..o

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 07:23 AM
  2. Explain this C code in english
    By soadlink in forum C Programming
    Replies: 16
    Last Post: 08-31-2006, 12:48 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Seems like correct code, but results are not right...
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 02-13-2003, 01:33 PM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM