C - Why are my variables retaining the value 0?

My variables are assigned 0 instead of what I type. What am I doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <math.h>
void main(){

//Declaring variables to hold x and y coordinate of the users choice. *A set of 3 coordinates.
float xP1,xP2,xP3;
    float yP1,yP2,yP3;

    //Giving user instructions

    //Getting data for the 1st coordinate.
    printf("Input the x-coordinate of the first point:");
        scanf("%f", &xP1);
            printf("Input the y-coordinate of the first point:");
                scanf("%f", &yP1);

    //Getting data for the 2nd coordinate.
   printf("\nInput the x-coordinate of the second point:");
        scanf("%f", &xP2);
            printf("Input the y-coordinate of the second point:");
                scanf("%f", &yP2);

    //Getting data for the 3nd coordinate.
    printf("\nInput the x-coordinate of the third point:");
        scanf("%f", &xP3);
            printf("Input the y-coordinate of the third point:");
                scanf("%f", &yP3);

//Determinig Distance of the 3 sides formed by traingle
float side1,side2,side3;
    side1 = sqrt(pow((xP1-xP2),2) - pow((yP1-yP2),2) );
    side2 = sqrt(pow((xP1-xP3),2) - pow((yP1-yP3),2) );
    side3 = sqrt(pow((xP2-xP3),2) - pow((yP2-yP3),2) );

    //Determing The Area using Herons Formulas
    float s = ((side1+side2+side3)/2 ); //Perimeter
        float area = sqrt(s * (s - side1)*(s - side2)*(s-side3)); //area


printf("\nThe area of the resulting triangle formed by your vertices is: %f", area);


}
1
2
side1 = sqrt(pow((xP1-xP2),2) - pow((yP1-yP2),2) );
                            //↑What?  
Same for other 2

You are somewhat lucky to get 0. It is NaN for majority of possible input.
Last edited on
What are you entering into the 3 sets of variables?

What do you mean by: "My variables are assigned 0 instead of what I type"? Where are you printing the variables to show they're zero instead of the assigned type?



Nvm. I solved it thanks MiNipa
Last edited on
Topic archived. No new replies allowed.