Help! right triangle

This code is supposed to determine whether the sum of the squares is a right triangle or not, and i cant figure out for the life of me why its not working.


#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
double a, b, c, right;

cin >> a >> b >> c;

cout << fixed << showpoint << setprecision(2);

// pythagorean theorem
right = sqrt(pow(a, 2) + pow(b, 2));

cout << right << " " << c << endl << endl;

if (right == c)
{
cout << "right triangle";
}

else
{
cout << "not";
}

return 0;

}
Last edited on
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
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>

int main()
{
    std::cout << "enter the three sides of the triangle: " ;
    double a, b, c ;
    std::cin >> a >> b >> c; // for now, we will assume that this succeeds
                             // (that the user enters three numbers)

    if( a>0 && b>0 && c>0 )
    {
        // make c the largest of the three sides
        if( a > b ) std::swap(a,b) ;
        if( b > c ) std::swap(b,c) ;

        if( c < (a+b) ) // if a, b,c form a triangle
        {
            const double hypot = std::sqrt( a*a + b*b ) ;
            std::cout << std::fixed << std::setprecision(2)
                      << hypot << ' ' << c << '\n' ;

            const double delta = 0.005 ; // floating point calculations are approximate
                                         // tolerance  roughly up to the second digit after the decimal point

            if( std::abs( hypot - c ) < delta ) std::cout << "right angled\n" ;
            else std::cout << "not right angled\n" ;
        }

        else std::cout << a << ", " << b << ", " << c << " does not form a  triangle\n" ;
    }

    else std::cout << "sides of the triangle must be positive\n" ;
}
Thanks so much!
Topic archived. No new replies allowed.