Thread: Using 2 functions to get 1 result

  1. #1
    Join Date
    Sep 2005

    Using 2 functions to get 1 result

    I have the following program
    #include <math.h>
    #include <stdio.h>
    #define PI 3.14159
    /* Function prototypes */
    void instruct(void);
     * Displays instructions to a user of program to compute the
     * area and circumference of the open-top cylindrical
     * container.
       printf("This program determines the cost of producing an\n");
       printf("open-top cylindrical container.\n\n");
       printf("To use this program, we first must determine the\n");
       printf("radius of the base of the open-top cylindrical container\n\n");
       printf("So please enter the radius of the base after the prompt:\n");  
    int main(void)
    After the instructions I would like to have the following function to compute the surface area of a cylinder. My teacher is instructing me to have to call the function from MAIN. How do I do this?

    #include <math.h>
    #include <stdio.h>
    #define PI 3.14159
    int main(void)
    double radius;
    double height;
    double surface_area;
    double base;
    double length;
    printf("Enter radius > ");
    scanf("%lf", &radius);
    printf("Enter the height > ");
    scanf("%lf", &height);
    base = (PI * pow(radius, 2));
    length = (2.0 * PI * radius) * height;
    surface_area = base + length;
    printf("The surface area is %5.2f.\n",

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Well, you see how you called the function instruct from main - when you call it, the instructions are printed out, and then control of the program goes right back to main, at the point right after the call to instruct() was made. Now it would be at this point you could get the user input as before, call your function (whatever the name of it is), remembering to pass the relevant data along with the call, and then it will return the answer when it is done computing it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. Wrong declaration, Right result ?
    By The SharK in forum C++ Programming
    Replies: 14
    Last Post: 10-24-2005, 01:11 PM
  3. Type casting
    By Lionmane in forum C Programming
    Replies: 28
    Last Post: 08-20-2005, 02:16 PM
  4. need help on Calculator program in C
    By deathscyth129 in forum C Programming
    Replies: 8
    Last Post: 01-08-2005, 07:50 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM