### Right triangle output problems

Hey guys/gals, I could use some help in finishing my code I need to be able to input whatever numbers to get a right triangle and also numbers that will show it is not a right triangle but I am stuck on what to do next. any help is appreciated.
here is what I have so far:

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

using namespace std;

int main (void)
{
short a, b, c;

cout<<"Enter side a: " <<endl;
cin>>a;
cout<<endl;
cout<<"Enter side b: " <<endl;
cin>>b;
cout<<endl;
cout<<"Enter side c: "<<endl;
cin>>c;
cout<<endl;

if (cin.fail()==true)
{
cout<<"Error, this is not a numericle value."<<endl;
cin.clear();
cin.ignore(50, '\n');
}
else if (a,b,c <=0)
{
cout<<"Has to be a positive number."<<endl;
}
else
{
a^2 == b^2 + c^2;
b^2 == a^2 + c^2;
c^2 == a^2 + b^2;

(a^2==b^2+c^2) || (b^2==a^2+c^2) || (c^2==a^2+b^2);

cout << "Press any key to exit." << endl;
}

cin.ignore(2) ;
return 0;
}
Hey rusty4118. A first note, when posting code please use code tags which can be found to the right of the input box. (Hint: the <> button.)

A quick question, what are you trying to do with this program?
 ``12345`` ``````a^2 == b^2 + c^2; b^2 == a^2 + c^2; c^2 == a^2 + b^2; (a^2==b^2+c^2) || (b^2==a^2+c^2) || (c^2==a^2+b^2);``````

These bits are meaningless in the context in which you used them. The equality operator will evaluate to true if it is a right triangle (in at least one of those scenarios), but you do nothing with it.

Also, is there a reason you declare a, b, and c as short? Wouldn't it better be suited as unsigned int? (Unless you want a length cap of 32767)
Hi rusty4118, I need to clarify something. The aim of this program is to check if the user's lengths input is a right-angle triangle? Because not all inputs can be a right-angle triangle. It must satisfy this condition: a^2 + b^2 = c^2 (where c is the longest length).

Like what Thumper has mention, you need not check all:
 ``123`` ``````a^2 == b^2 + c^2; b^2 == a^2 + c^2; c^2 == a^2 + b^2;``````

Simply find out the longest length input by the user, and apply the formula. By this, you only need to check just once.

For example:
 ``12345678910111213141516171819202122232425262728`` ``````#include "stdafx.h" #include #include #include #include using namespace std; int main() { vector length; //Storing the lengths of the triangle double tmp; for(int i = 0; i < 3; i++) { cout << "Key in the length: "; cin >> tmp; length.push_back(tmp); } sort(length.begin(), length.end()); //Sorting the lengths in ascending order if ((pow(length.at(0),2)+pow(length.at(1),2)) == pow(length.at(2),2)) cout << "Is a right-angle" << endl; else cout << "Is NOT right-angle" << endl; system("pause"); return 0; }``````

Topic archived. No new replies allowed.