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*/
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*/
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()