Use three separate if() statements for the tests (one for each possible hypotenuse). Remember if you don't find a right triangle in any of the three if() statements for a fourth if() statement to print a message saying the sides don't form a right triangle. Do not use if-else() for this, just four if() statements.
Your fourth if() statement may not test the sides entered by the user. You must
REMEMBER if you have seen a right triangle or not.
Could anyone explain what does the fourth statement mean and give me a hint?
I have no idea what should I do now because of the restriction for the fourth if statement.
Another question is when I declared the variables as integer, the calculation for the pow(x,y) was incorrect. For example, the result for 5 square became 24 instead of 25. Does this mean only float is working for the pow() function?
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
float side1, side2, side3, hy1, hy2, hy3;
cout << "Enter the length of the three sides: " << flush;
cin >> side1;
cin >> side2;
cin >> side3;
cout << endl;
side1 = pow (side1, 2);
side2 = pow (side2, 2);
side3 = pow (side3, 2);
hy1 = side1 + side2;
hy2 = side2 + side3;
hy3 = side1 + side3;
if (side1 == hy2)
{
cout << "It is a right triangle.";
}
if (side2 == hy3)
{
cout << "It is a right triangle.";
}
if (side3 == hy1)
{
cout << "It is a right triangle.";
}
if ( )
// I'm stuck here since I can't use the user input as the test condition.
{
if (side1 == hy2)
{
cout << "It is a right triangle.";
}
if (side2 == hy3)
{
cout << "It is a right triangle.";
}
if (side3 == hy1)
{
cout << "It is a right triangle.";
}
1 2 3 4 5 6 7 8 9 10 11 12
if (side1 == hy2)
{
cout << "It is a right triangle.";
if (side2 == hy3)
{
cout << "It is a right triangle.";
if (side3 == hy1)
{
cout << "It is a right triangle.";
}
}
}