#include <stdio.h>
#include <math.h>

int main(void)
{

    /* declare necessary variables for the (x,y) coordinates */

    float x1;
    float x2;
    float x3;
    float y1;
    float y2;
    float y3;

    /* declare the distance variables. The distance will be calculated using the user input values */

    float distance1;
    float distance2;
    float distance3;

    /* declare the Area veriable. The Area will be calculated using the distnace values. */

    float Area;


    /* Create Print/Scan Functions which allow the user in iput the x and y coordinates into the program. */

    printf("\nPlease input the x-coordinate of the first point: \n");
    scanf("%f", &x1);

    printf("\nPlease input the y-coordinate of the first point: \n");
    scanf("%f", &y1);

    printf("\nPlease input the x-coordinate of the second point: \n");
    scanf("%f", &x2);

    printf("\nPlease input the y-coordinate of the second point: \n");
    scanf("%f", &y2);

    printf("\nPlease input the x-coordinate of the third point: \n");
    scanf("%f", &x3);

    printf("\nPlease input the y-coordinate of the third point: \n");
    scanf("%f", &y3);


    /* write distance formulas which calculate the legnth of each of the three sides of the triangle using the user inputs. */

    distance1=(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
    distance2=(sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2)));
    distance3=(sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3)));


    /* Create Print Functions to print the distance of each of the three sides of the trianlge. */

    printf("\n\nThe distance of side a is:%.2f\n\n",distance1);
    printf("\n\nThe distance of side b is:%.2f\n\n",distance2);
    printf("\n\nThe distance of side c is:%.2f\n\n",distance3);



    /* Create IF Statements for when the coordinates entered by the user do not form a triangle. */


        /* The first way that the three points do not form a trianlge is if two or more of the points are the same */

        if ((x1==x2) && (y1==y2))
            printf("\n\n\nThe points (%.0f,%.0f), (%.0f,%.0f), and (%.0f,%.0f) do not form a triangle because (x1,y1) and (x2,y2) are the same."
                , x1,y1,x2,y2,x3,y3);

        if ((x2==x3) && (y2==y3))
            printf("\n\n\nThe points (%.0f,%.0f), (%.0f,%.0f), and (%.0f,%.0f) do not form a triangle because (x2,y2) and (x3,y3) are the same."
                , x1,y1,x2,y2,x3,y3);

        if ((x1==x3) && (y1==y3))
            printf("\n\n\nThe points (%.0f,%.0f), (%.0f,%.0f), and (%.0f,%.0f) do not form a triangle because (x1,y1) and (x3,y3) are the same."
                , x1,y1,x2,y2,x3,y3);


        /* The second way that the three points do not form a trianlge is if two or more of the points lie on the same line */

        if (((y2-y1)/(x2-x1))==((y3-y2)/(x3-x2)))
            printf("\n\n\nThe points (%.0f,%.0f), (%.0f,%.0f), and (%.0f,%.0f) do not form a triangle because they lie along the same line."
                , x1,y1,x2,y2,x3,y3);


    /* Use Heron's formula which calculated Area using distance of side lengths. */

    Area=(sqrt(((distance1+distance2+distance3)*(((-1)*distance1)+distance2+distance3)*(distance1-distance2+distance3)
               *(distance1+distance2-distance3))/16));

    /* Create a print function which prints the Area of the trianlge */

    printf("\n\n\nThe area of the triagle made with (%.0f,%.0f), (%.0f,%.0f), and (%.0f,%.0f) is %.2f.\n\n\n", x1,y1,x2,y2,x3,y3,Area);

    return 0;
}
