Hi everyone, I'm a little bit stumped. Please forgive me if the code is poorly written, I did learn C++ about 4 years ago and I currently have to take a C course so I am very rusty.
I'm getting an error I can't figure out. I will give you a rundown of what the program is supposed to do.
The user enters 6 numbers that represent x and y coordinates, with this I need to determine the area of the triangle that is formed.
This is what I currently have, included in this is a rule that checks to see if no triangle is formed in which case it tells that to the user. If all things are good then it calculates the area.
The error I'm getting when compiling is as follows: error: called object "S - a" is not a function
I'm also having problems with the values not coming out as decimal points, for example if you enter:
x1 = 3
x2 = 2
y1 = 4
y2 = 5
The answer to this is definitely 1.41 but the program spits out -2.00.
Code:
#include <stdio.h>
int main (void)
{
/*Here we declare our values*/
int x1;
int x2;
int x3;
int y1;
int y2;
int y3;
float a;
float b;
float c;
float S;
float T;
/*Here we will ask the user for the co-ordinates of 3 points*/
printf("Input the x-coordinate of the first point: ");
scanf("%d", &x1);
printf("Input the y-coordinate of the first point: ");
scanf("%d", &y1);
printf("Input the x-coordinate of the second point: ");
scanf("%d", &x2);
printf("Input the y-coordinate of the second point: ");
scanf("%d", &y2);
printf("Input the x-coordinate of the third point: ");
scanf("%d", &x3);
printf("Input the y-coordinate of the third point: ");
scanf("%d", &y3);
/*We will now compute the distance between each point in order to obtain 3 lengths which we will then use in Heron's Formula to solve for the area of the triangle*/
a=((x2-x1)^2+(y2-y1)^2)^1/2;
scanf("%f", &a);
b=((x3-x1)^2+(y3-y1)^2)^1/2;
scanf("%f", &b);
c=((x3-x2)^2+(y3-y2)^2)^1/2;
scanf("%f", &c);
printf("Side a is: %5.2f units.", a);
printf("Side b is: %5.2f units.", b);
printf("Side c is: %5.2f units.", c);
if ((a+b)>c)
{
printf("The sides do not fulfill the requirements of the inequality theorum, it is not possible to form a triangle with the specified co-ordinates.");
}
else
if ((b+c)>a)
{
printf("The sides do not fulfill the requirements of the inequality theorum, it is not possible to form a triangle with the specified co-ordinates.");
}
else
if ((a+c)>b)
{
printf("The sides do not fulfill the requirements of the inequality theorum, it is not possible to form a triangle with the specified co-ordinates.");
}
else
{
/*Here we are solving for "S", which will be used in Heron's formula*/
S=((a+b+c)/2);
scanf("%f", &S);
/*Now we use Heron's formula to solve for the area, T*/
T=((S*(S-a)*(S-b)*(S-c)))^1/2;
printf ("The area of your triangle is: %5.2f units.", T);
}
return 0;
}
Where am I faulting, also since I don't understand exactly why its happening if you could provide me with a reason (if its not too much trouble) I would prefer that. I'd rather understand than just get an answer.
Thank you in advance.