
/*        Description: A re-write of the triangle analyzer program,
        making use of functions where appropriate and possible.

        Try adding the other functions we developed in class.

*/

/* includes and defines */
#include <stdio.h>
#include <math.h>

/* function prototypes go here: */
double area_of_triangle( double, double, double );
void show_instructions(void);
void display_results(double,double,double,double);

/* function definitions */
int main(void) {
   /* main function or "driver" */
   double a, b, c;	
   double result;

   show_instructions();

   printf("Enter the 3 sides: ");
   scanf("%lf%lf%lf", &a, &b, &c );

   result = area_of_triangle(a,b,c);
   display_results(a,b,c,result);
   
   return 0;
}

/* other function definitions go here: */
double area_of_triangle (double x, double y, double z ) {
   /* this function computes the area of a 
      triangle with sides x, y, and z */

   double s;	/* half perimeter */
   double area;	/* area of triangle */

   s = (x + y + z ) / 2;

   area = sqrt( s*(s-x)*(s-y)*(s-z) );

   return area;
}

void show_instructions(void) {
   printf("This program calculates the area of any triangle.\n");
   printf("You have to enter 3 real numbers, representing\n");
   printf("the 3 sides of a triangle.\n");

   return;
}

void display_results(double x, double y, double z, double area) {
   printf("\n\nYou entered %.1f %.1f %.1f for the sides.\n", x, y, z);
   printf("The area for this triangle is %.1f\n", area);

   return;
}
