/*  Kris Snyder
    8263577
    Project: Area of a Triangle
    October 17, 2015            */

#include <stdio.h>//Tells the compiler to define certain functions
#include <math.h>//Tells the compiler to define certain mathematical functions


int main()//States the main function
{
    float x1, x2, x3, y1, y2, y3, area;//Declaration of the variables used
    float slope12, slope23, slope13;

    printf("Enter the value for x1\n");//Prompts user to enter value for x1
    scanf("%f", &x1);//Scans the value that the user enters

    printf("Enter the value for y1\n");//Prompts user to enter value for y1
    scanf("%f", &y1);

    do //Initiates a do/ while loop which prompts the program to simultaneously carry out two functions
    {
        printf("Enter the value for x2\n");//Prompts user to enter value for x2
        scanf("%f", &x2);//Scans the value that the user enters

        printf("Enter the value for y2\n");//Prompts user to enter value for y2
        scanf("%f", &y2);//Scans the value that the user enters
        if(x1==x2 && y1==y2)//A function that intiate a loop only if the conditions are met
        {
            printf("Error the points are the same\n"); //Error message that is printed if the conditions above are satisfied
        }
    }while(x1==x2 && y1==y2); /*Tells the program to check whether the first and second x and y values are equal
                                while simultaneously caring out the loop*/
    do //Initiates a do/ while loop which prompts the program to simultaneously carry out two functions
    {
        printf("Enter the value for x3\n");//Prompts user to enter value for x3
        scanf("%f", &x3);//Scans the value that the user enters

        printf("Enter the value for y3\n");//Prompts user to enter value for y3
        scanf("%f", &y3);//Scans the value that the user enters
        if(x2==x3 && y2==y3)//An if loop that only if the conditions are met will print the error message below
        {
            printf("Error the points are the same\n");//Error message that is printed if the conditions above are satisfied
        }
    }while(x2==x3 && y2==y3); /*Tells the program to check whether the second and third x and y values are equal
                                while simultaneously caring out the loop*/


    slope12 =((y2-y1)/(x2-x1));//Calculates the slope of of triangle side 12
    slope23 =((y3-y2)/(x3-x2));//Calculates the slope of of triangle side 23
    slope13 =((y3-y1)/(x3-x1));//Calculates the slope of of triangle side 13



    if((slope12==slope23)||(slope23==slope13)||(slope12==slope13))//A function that intiate a loop only if the conditions are met
    {
        printf("Error points are collinear\n");//Error message that is printed if the conditions above are satisfied
    }

    else area=(((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/2);//A function that is initiated if none of the slopes are equal to each other
    {
        printf("The area of the triangle is %f\n", fabs(area));//Displays the area calculated using the points entered
    }


   return 0;//Closes the main funtion
}
