-1

So my program here is suppose to take 3 values and store it in the variables Ax,Ay etc... but for some reason it keeps returning 0.00 for the area and from what I see all of this code should return a proper area, it applies the distance formula and heron's formula for area

#include <stdio.h>
#include <math.h>

int main(void) {
    float Ax,Ay,Bx,By,Cx,Cy,A,B,C,side,area;
    printf("hello inPut x,y coords");
    printf("input 3 numbers for your x coordinates");
    scanf("%f%f%f",&Ax,&Bx,&Cx );
    printf("input 3 numbers for your y coordinates");
    scanf("%f%f%f",&Ay,&By,&Cy);

    A=sqrt(((Bx-Ax)*(Bx-Ax))+((By-Ay)*(By-Ay)));
    B=sqrt(((Cx-Bx)*(Cx-Bx))+((Cy-By)*(Cy-By)));
    C=sqrt(((Ax-Cx)*(Ax-Cx))+((Ay-Cy)*(Ay-Cy)));



    side=((A+B+C)/2);

    area=sqrt(side*(side-A)*(side-B)*(side-C));
    printf("n AREA OF TRIANGLE IS %f",area);

}

The Pseudo-Code of what it's suppose to do is this:

Take 3 numbers like 
5,7,8
These first three numbers are now stored in Ax,Bx,Cx (Ax=5,Bx=7,Cx=8)
Take 3 more numberss for the y coordinate (1,2,3)
Store numbers in Ay By Cy (Ay =1, By=2, Cy=3)

take these values and calculate the distance between them by using this formula:

sqrt((Bx-Ax)^2+(By-Ay)^2)
repeat this 2 more time for the other numbers

now it calculates the perimeter of the triangle, and halves it , then inputs it into the heron formula to get the area.

Ideally these values should give an area > 0.
user3655510
  • 81
  • 1
  • 3
  • 10
  • Please edit your question and specify your input and your expected output. – Jabberwocky Sep 29 '15 at 06:58
  • 1
    Have you checked the input values yet? – Ignacio Vazquez-Abrams Sep 29 '15 at 07:03
  • What are the values you use to evaluate? As the return type is `int`, I would expect a rounding or trunctaion issue here, especially if the area is smaller than one. – Codor Sep 29 '15 at 07:03
  • In my example : http://ideone.com/b8OOp9 `side` always equals `c` so that `area` always results in a zero value. Check your algorithm. – Pierre Begon Sep 29 '15 at 07:07
  • ive checked the input values, and it returns 0 no matter what, I'm not sure why it would keep returning C, if the algorithm is based off of the required math equations – user3655510 Sep 29 '15 at 07:11
  • 1
    @buffo: Your input (1,4) (2,5), (3,6) defines a zero-area triangle where all three sides are parallel, so that's not a good example. – M Oehm Sep 29 '15 at 07:13
  • @user3655510: Please show what input values you're using. – Mark Dickinson Sep 29 '15 at 07:13
  • @MOehm: ouch! That was a mathematical mastepiece ;) your code with input 5,6,7 and 1,2,3 results in 0.5 for me. http://ideone.com/Yp7Scv – Pierre Begon Sep 29 '15 at 07:14
  • 1
    @buffo: Well, it was a typical case of "Now make up six numbers on the spot", I'd say. :-) FWIW, the few inputs I've checked had good answers, too. – M Oehm Sep 29 '15 at 07:24
  • Please use newlines to format your print statements. It's also a good idea to echo the input when you get unexpected results in oder to check that you are really the numbers you think you're using. – M Oehm Sep 29 '15 at 07:25

1 Answers1

2

Your code works fine. I try it with this tripples 1.2 2.8 7.8 and 1.3 2.3 0.1 and this is ok. Perhaps do you use "," instead of "." for decimal separation ...

Christophe
  • 21
  • 1
  • Maybe you could expand your answer to include why `.` is the separator here instead `,`. Also this http://stackoverflow.com/questions/13919817/sscanf-and-locales-how-does-one-really-parse-things-like-3-14 might give him some insight. – RedX Sep 29 '15 at 08:22