problems with functions

So here is my assignment:

Purpose:
Implement algorithms using functions (topic of chapters 5 of the course textbook).

Program Description:
Compute the perimeter, area, and centroid of a triangle defined by three points specified by the user.

Program Requirements:
1. Write two functions which have six parameters (x and y values of each of the points) and compute the area and perimeter of the triangle. Write two functions which have three parameters and compute the x and y values of the centroid.
2. Prompt the user for the coordinates (x and y values) of three points and get the user’s input data.
3. Compute the area, perimeter, and centroid of the triangle defined by the user-specified points.
4. Print the points the user specified as well as the perimeter, area, and centroid of the triangle with three digits to the right of the decimal point for all values.
5. Exit with no error upon completion.


Here is what i have written so far:

//*Programming assignment 2*//

#include <stdio.h>

//float distance(float a, float b, float c, float d, float e, float f); /*function prototype*/
float perimeter(float side11, float side22, float side33); /*function prototype*/
float area(float x, float y, float z); /*function prototype*/
float centroid(float a, float b, float c, float d, float e, float f); /*function prototype*/

/*function main begins program execution*/
int main(void)
{
float point1; /*first point*/
float point2; /*second point*/
float point3; /*third point*/
float point4; /*fourth point*/
float point5; /*fifth point*/
float point6; /*sixth point*/

printf("Enter coordinates of point A (x y): "); /*Ask user for point A*/
scanf("%f %f", &point1, &point2); /*read point A*/
printf("Enter coordinates of point B (x y): "); /*Ask user for point B*/
scanf("%f %f", &point3, &point4); /*read point B*/
printf("Enter coordinates of point C (x y): "); /*Ask user for point C*/
scanf("%f %f", &point5, &point6); /*read point C*/

printf("Perimeter is%d\n", perimeter(allsides));

return 0;
}

/*Distance function*/
float perimeter(float allsides)
{
float side1, side2, side3, side11, side22, side33;

side1 = pow((point3 - point1),2) + pow((point4 - point 2),2);
side2 = pow((point5 - point3),2) + pow((point6 - point 4),2);
side3 = pow((point1 - point5),2) + pow((point2 - point 6),2);

side11 = sqrt(side1);
side22 = sqrt(side2);
side33 = sqrt(side3);

allsides = side11 + side22 + side33;

return perimeter;

}

IM LOST! PLEASE HELP!!

Thanks,

Jennifer
Ok, looking over you code, I noticed a couple of things...

1.) Use [code][/code] tags next time (put them around your code)
2.) You are trying to use local variables inside of functions (point1, point2, etc) you will have to pass these as parameters in order to be able to use them
3.) What are you trying to return from perimeter? You don't have a variable called perimeter to return
4.) Unless you are required to use C, I would suggest using <iostream> instead to get data, as it is easier to use then scanf()
Topic archived. No new replies allowed.