Thread: No experience with menus and calling functions... HELP

  1. #1
    Registered User
    Join Date
    Sep 2004

    No experience with menus and calling functions... HELP

    I just finished my assigned programs that each draws a simple shape with the users desired character.

    Now I have to make a menu based on 6 printf's which lets the user pick which figure to draw and if he/she wants to exit. The menu has to be based on calling each drawing program as a function. The programs are already in function form but I have programmers blockage in terms of what to do after the users picks a selection from 1 to 6. The 6th printf is for the user to exit the program/menu.

    #include <stdio.h>
    #include <stdlib.h>
    int main ()
    { int option, x, y, num, size;
    // x y num and size are variables from each of the programs//
    char symbol;
    char c;
    void cuadrado (int, char);
        printf ("1. Draw a square");
        printf ("2. Draw a Diamond");
        printf ("3. Draw a triangle left justified");
        printf ("4. Draw a triangle right justified");
        printf ("5. Draw an hour glass");
        printf ("6. Exit");
        scanf ("%d", &option);
    Basically I know that for each option I have to call the appropiate function, such as
    square (int, char)
    But also each figure requires that the user input the size of the figure(rows, columns etc.) and what character they want the figure to be drawn in. I just don't know where to start... But the general order would be foir the user to input his selection, then to be asked a number between 1-20 and then to be asked the character they want for all the figures.

    Any help no matter how minute will be gratly appreciated.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Break the program down into small steps. I like to use pseudocode, or, writing my thoughts out in a not-really-code-but-kinda-code manner:
    display menu of choices
    get choice from user
    call function based on choice
    Ok, now I break this down further perhaps:
    display menu
    get choice
    switch choice
        choice square: call square function
        choice diamond: call diamond function
        choice triangle: call triangle function
        ...and so on...
    Now, since I haven't anything on the square function, let's see what it might be:
    ask user what character they want it to be drawn from
    get input from user
    ask user width of square
    get input from user
    ask user height of square
    draw the top row
    draw middle rows
    draw the bottom row
    Now let's break the drawing part down even further:
    draw top row
    draw height - 2 middle rows
    draw bottom row
    Even further:
    /* top row */
    repeat width times:
        draw users's character of choice
    go to new line
    /* middle rows */
    repeat height - 2 times
        draw user's character of choice
        draw width - 2 spaces
        draw usere's character of choice
        go to new line
    /* bottom line */
    repeat width times:
        draw users's character of choice
    go to new line
    It helps a great deal to think of the steps you need to do each task. Start with the overview of the entire project. Breat it into steps. Break each step into steps. Repeat until you can't break it down any more. Code it.

    People crack me up. Someone tried to mod me down as unhelpful on this post. Here's the comment that was left:
    actually "you're" not doing anything for me; if you don't like keep stepping; yall need to get a life
    This amuses me to no end. I give a huge example of how to break things into smaller steps, and someone doesn't think that's help. That's a riot, especially considering the OP stated that "any help no matter how minute" would be appreciated.

    It is to laugh.

    Last edited by quzah; 11-05-2004 at 01:31 PM.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed