Click here to Skip to main content
15,887,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include<stdio.h>
#include<math.h>

float dist(int ,int, int, int);
float dist(int x1, int y1, int x2, int y2)
    {
        float x;
        x = sqrt(pow((x1-x2),2)+pow((y1-y2),2));
        return x;
    }

float area(float, float, float);
float area(float x, float y, float z)
    {
        float s,w;
        s = (x+y+z)/3;
        w = s*(s-x)*(s-y)*(s-z);
        return sqrt(w);
    }


int main(){
    int x1, x2, y1, y2, z1, x3, y3;
    float p,q,r;
    printf("Enter x1 y1 x2 y2 x3 y3\n");
    scanf("%d %d %d %d %d %d",&x1, &y1, &x2, &y2, &x3, &y3);
    p = dist (x1, y1, x2, y2);
    q = dist (x2, y2, x3, y3);
    r = dist (x3, y3, x1, y1);
    printf("%f",area(p,q,r));
   return 0;
}




When I give input (0,0) (0,1) (1,0) it gives this error
-1.#IND00
. If someone could help I would be really obliged. Thanks

What I have tried:

I can't figure out what to do with this.
Posted
Updated 27-Sep-20 14:10pm
Comments
OriginalGriff 27-Sep-20 3:09am    
Answer updated.

Quote:
I can't figure out what to do with this.

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

1.11 — Debugging your program (stepping and breakpoints) | Learn C++[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
 
Share this answer
 
What is the result when you take the square root of minus one?

An imaginary number of course -0 there is a whole branch of maths devoted to such things: complex numbers[^] and they are pretty useful.

But not when you are trying to work out the distance between two points ...

When you get an error you don't understand, google it: #IND00 Google[^] - that lead me right here: -1.#IND00 problem in a programm. : C_Programming[^] which explains it.


Quote:
Ty but haven't I squared the result and so the sqrt function would always get positive value as its parameter?

What if x is one, and y, z are both zero?
C++
s = (x+y+z)/3;
w = s*(s-x)*(s-y)*(s-z);
Is w positive or negative?
 
Share this answer
 
v2
Comments
Luc Pattyn 27-Sep-20 20:11pm    
It is rather hard to create a triangle having two but not three sides with zero length...
OriginalGriff 28-Sep-20 2:53am    
Geometry is a lie! :laugh:
Heron won't like what you did to his beautiful formula...

The way you wrote it every equilateral triangle would have zero area ?!?!

:)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900