# Using 2 functions to get 1 result

This is a discussion on Using 2 functions to get 1 result within the C Programming forums, part of the General Programming Boards category; I have the following program Code: #include <math.h> #include <stdio.h> #define PI 3.14159 /* Function prototypes */ void instruct(void); /* ...

1. ## Using 2 functions to get 1 result

I have the following program
Code:
```#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.
*/
void
instruct(void)
{
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)
{
instruct();

return(0);
}```
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?

Code:
```#include <math.h>
#include <stdio.h>
#define PI 3.14159

int main(void)
{
double height;
double surface_area;
double base;
double length;

printf("Enter 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",
surface_area);

return(0);
}```

2. 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