# Was recommended here, I'm learning C and require some help.

• 09-25-2012
Seeki
Was recommended here, I'm learning C and require some help.
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.

• 09-25-2012
qny
In C there is no exponentiation symbol. You either call the pow() function (declared in <math.h>) or, for the numbers you are raising to the power 2, multiply the number by itself.

Also 1/2 is integer division; you need to make a floating-point division.

Code:

``` /* a = ((x2-x1)^2 + (y2-y1)^2) ^ 1/2;                    NO!!! */     a = pow((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1), 1.0/2); /* ok */```