A beginner's problem !

• 02-26-2011
Coca cola
A beginner's problem !
Code:

```Hi everyone. Well, I have  just started C++ programming and I solved one problem partly, actually the user enters three numbers and I must check if there is a right triangle with sides whose lengths are those three numbers. The program works for integer .For example, if I enter :3,4,5 it works but when I enter 0.3 , 0.4 , 0.5 it says there there us no right traingle with these lenghts but it should be ! Here is the program : #include<iostream> using namespace std; int main(){     double a,b,c;     cout<<"Please enter three numbers";     cin>>a>>b>>c;     if(a*a+b*b==c*c || a*a+c*c==b*b || c*c+b*b==a*a)     cout<<"There is a right triangle with these lenghts";     else     cout<<"There is not ... "; return 0; }```
• 02-26-2011
Elysia
In the future, please put your actual message text outside the code tags. The code tags are for code only.

Now, as for your problem. You basically have to remember that precision in a computer isn't unlimited, contrary to algebra. The chance that a*a + c*c equals exactly b*b is small. It will more likely be roughly equal to b*b. So you have to basically do

if (abs(a*a + c*c - b*b) <= 0.0001)

Where 0.0001 is some small range that works well.
• 02-27-2011
Coca cola
Thank you very much ! I will ...