advice/assistance using functions

I have to write a program that calculates the perimeter, semiperimeter, area and centroid of a triangle using coordinates input by user. Some of the requirements for the program are: "write 2 functions which have 6 parameters (x and y values of each of the points) and compute the area and perimeter of triangle. write 2 functions which have 3 parameters and compute the x and y values of the centroid." I have written a function that computes the side of a triangle which is:

/*programming assignment 2*/

#include <stdio.h>
#include <math.h>

double distance(double x1, double y1, double x2, double y2);


int main(void)
{
double point1, point2, point3, point4, point5, point6;

printf("Enter coordinates of point A (x y):");
scanf("%lf%lf", &point1, &point2);
printf("Enter coordinates of point B (x y):");
scanf("%lf%lf", &point3, &point4);
printf("Enter coordinates of point C (x y):");
scanf("%lf%lf", &point5, &point6);

return 0;

}

double distance(double x1, double y1, double x2, double y2)

{
double side1, side2;

side1 = pow((x2-x1),2) + pow((y2-y1),2);

side2 = sqrt(side1);

return side2;

}



My first question is: How do I use the values returned in the distance function in another function to determine perimeter. And after that, use the values from the perimeter function to determine area in the area function.

My second question is: How do print the coordinates the user input in parentheses? For example user inputs 3,4 as coordiantes for point A. My output has to be "Point A = (3.000, 4.000). I forgot to mention that this program has to be written in C and not C++

Any help would be greatly appreciated!!!
well, for your first question, you need to create a variable in main that will accept the return value, and then you can use that same variable as an argument to the next function.


for the second question, just a liberal use of "
cout << "Point A = (" << variable1 << "," << variable2 << ")"

as for outputting 3 as 3.000

check into

cout << fixed << showpoint << setprecision(3)
(remember to use #include <iomanip> for these stream modifiers.


Topic archived. No new replies allowed.