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>
#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
{
constdouble hypot = std::sqrt( a*a + b*b ) ;
std::cout << std::fixed << std::setprecision(2)
<< hypot << ' ' << c << '\n' ;
constdouble 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" ;
}