Thread: Help ASAP With Multiple Functions with Input/Output Parameters

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    39

    Angry Help ASAP With Multiple Functions with Input/Output Parameters

    Ok so i got this code working but then i realized that my teacher is a lame and wont accept it bc its dooesnt use Multiple Functions with Input/Output Parameters and i have no idea how to do that :/ i wondering if you could give me a example or idk :/

    heres the problem question Write a menu program that will print various formulas and do calculations. For each menu choice, display the formula and prompt for the necessary values. Then calculate and print the area and the perimeter.

    Your program must have 5 functions as follow:
    1) int getMenuChoice( ); // display the menu, get and return the choice.
    2) void Circle( double *radius, double *area, double *perimeter ); // display the formulas, get the radius, calculate the area and the perimeter, function should return the values through the output perimeters.
    3) void displayCircle( double radius, double area, double perimeter ); // display the all the values in a tabular format.
    4) void Rectangle( double *length, double *width, double *area, double *perimeter ); // display the formulas, get the length and the width, calculate the area and the perimeter, function should return the values through the output perimeters.
    5) void displayRectangle( double length, double width, double area, double perimeter ); // display the all the values in a tabular format.


    Code:
    #include <stdio.h>
    
    /*void DisplayMenu (void) ;
      int GetMenuChoice (void) ; 
      void Circle( double *radius, double *area, double *perimeter );    
      void displayCircle( double radius, double area, double perimeter );    
      void Rectangle( double *length, double *width, double *area, double *perimeter ); 
      void displayRectangle( double length, double width, double area, double perimeter */   
    
    
    /*void DisplayMenu (void) ;*/
      int GetMenuChoice (void) ; 
    int main(void)
    {
    char choice;
    
    do
    {
    printf("\n-------------Menu of Shapes---------------");
    printf("\n\'A\'Circle\n\'B\'Rectangle\n\'C\'Quit :");
    fflush(stdin);
    scanf("%c", &choice);
    
    /*int GetMenuChoice (void) ; */
    
    switch(choice)
    {
    case 'A':
    case 'a':
    /*void Circle( double *radius, double *area, double *perimeter ); */
    {
    printf("----------Proccessing Circle-----------\n\n");
    printf("Area of Circle = 3.14 * Radius * Radius\n");
    printf("Perimeter of Circle = 2 * 3.14 * Radius\n\n");
    float radius;
    printf("Enter the radius :");
    scanf("%f", &radius);
    
    /*void displayCircle( double radius, double area, double perimeter );*/
    
    printf("----------------Results----------------\n\n");
    printf("Radius is %.1f",radius);
    printf("\nArea of circle is %.1f", 3.14 * radius * radius);
    printf("\nPerimeter of circle is %.1f", 2 * 3.14 * radius);
    printf("\n\n------------------------------------------");
    break;
    }
    
    case 'B':
    case 'b':
    
    /*void Rectangle( double *length, double *width, double *area, double *perimeter ); */
    
    {
    printf("----------Proccessing Rectangle-----------\n\n");
    printf("Area of Rectangle = Length * Width\n");
    printf("Perimeter of Rectangle = 2*Length + 2*Width \n\n");     
    float length, width;
    printf("Enter the Length :");
    scanf("%f", &length);
    printf("Enter Width :");
    scanf("%f", &width);
    
    /*void displayRectangle( double length, double width, double area, double perimeter */ 
    
    printf("----------------Results----------------\n\n");
    printf("\nWidth is %.1f",width);
    printf("\nLength is %.1f",length);
    printf("\nArea of rectangle is %.1f", length * width);
    printf("\nPerimeter of rectangle is %.1f", 2 * (length + width));
    printf("\n\n------------------------------------------");
    break;
    }
    
    default :
    printf("\nInvalid choice");
    }
    }while(choice != 'c' && choice != 'C');
    
    return 0;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You have all of the function prototypes. Start by writing functions that match those. Then pass them what they need. Try that, and post your attempt.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    39
    can u give like a example because i have no idea what you mean by that bc i was sick and missed that lesson unfortunately :/

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    An example of what?
    Code:
    /*void DisplayMenu (void) ;
      int GetMenuChoice (void) ; 
      void Circle( double *radius, double *area, double *perimeter );    
      void displayCircle( double radius, double area, double perimeter );    
      void Rectangle( double *length, double *width, double *area, double *perimeter ); 
      void displayRectangle( double length, double width, double area, double perimeter */
    Make all of those functions. Like so:
    Code:
    void myfunction( void )
    {
        printf( "this function, named myfunction, returns void, takes no arguments\n" );
    }
    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Feb 2011
    Posts
    39
    kk thanks ill give it a try

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by 123456tacos View Post
    can u give like a example because i have no idea what you mean by that bc i was sick and missed that lesson unfortunately :/
    Y'know what... they have this totally amazing thing, been around for quite a while too... It's called a TextBook... They're litterally filled with information about various topics and most of it is highly informative... Heck, I bet you could even learn to programm in C from one of those!

    Missing a lesson is not an excuse.

  7. #7
    Registered User
    Join Date
    Feb 2011
    Posts
    39
    Quote Originally Posted by quzah View Post
    An example of what?
    Code:
    /*void DisplayMenu (void) ;
      int GetMenuChoice (void) ; 
      void Circle( double *radius, double *area, double *perimeter );    
      void displayCircle( double radius, double area, double perimeter );    
      void Rectangle( double *length, double *width, double *area, double *perimeter ); 
      void displayRectangle( double length, double width, double area, double perimeter */
    Make all of those functions. Like so:
    Code:
    void myfunction( void )
    {
        printf( "this function, named myfunction, returns void, takes no arguments\n" );
    }
    Quzah.
    anyways thanks for the help i figured it out

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-16-2008, 03:11 PM
  2. Replies: 5
    Last Post: 02-25-2008, 06:35 AM
  3. Functions! Need help ASAP plz!
    By andone in forum C Programming
    Replies: 2
    Last Post: 11-02-2006, 04:07 AM
  4. Replies: 3
    Last Post: 10-23-2006, 06:37 PM
  5. Strange characters in output Need Help ASAP
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 12-14-2003, 06:35 PM