Hello! I am new here and to programming as a whole. I am using GCC on Fedora to do a summer semeseter in C Programming. I am currently learning "if statements" while doing a program that calculates the area of a triangle. My problem is that the result is always "0". I am pretty sure the problem lies within my math, but I can't figure out how I have set it up wrong. Thanks for reading/looking.
I am using Heron's Formula. Here it is for reference:
area=sqrt(s(s-a)(s-b)(s-c)) where s=(a+b+c)/2
Code:
#include <stdio.h>
#include <math.h>
int main ()
{
float area, sideA, sideB, sideC, halfP;
printf("\n This program will calculate the area of a triangle.");
printf("Please enter the value for the first side: ");
scanf("%f", &sideA);
printf("Please enter the value for the second side: ");
scanf("%f", &sideB);
printf("Please enter the value for the third side: ");
scanf("%f", &sideC);
if (0 > sideA)
printf("The distance must be positive. \n");
else if (0 > sideB)
printf("The distance must be positive. \n");
else if (0 > sideC)
printf("The distance must be positive. \n");
else
halfP = (sideA+sideB +sideC)/2;
area = sqrt(halfP*(halfP-sideA)*(halfP-sideB)*(halfP-sideC));
printf("\n The area of the triangle is %f \n", &area);
return 0;
}