CODE
#include <iostream>
using namespace std;
struct pointType
{
int x;
int y;
};
void read(pointType& p);
bool isRigtTriangle(const pointType p1, const pointType p2, const pointType p3);
int main()
{
// please don't change stuff in here
pointType point1, point2, point3;
cout << "Enter two integers for point 1: " << flush;
read(point1);
cout << "Enter two integers for point 2: " << flush;
read(point2);
cout << "Enter two integers for point 3: " << flush;
read(point3);
if (isRigtTriangle(point1, point2, point3))
cout << "The three points form a right-angled triangle." << endl;
else
cout << "The three points don't form a right-angled triangle." << endl;
system("pause");
return 0;
}
void read(pointType& p)
{
cin >> p.x >> p.y;
}
bool isRigtTriangle(const pointType p1, const pointType p2, const pointType p3)
{
if((p1.x + p1.y * p1.x + p1.y) + (p2.x + p2.y * p2.x + p2.y) == (p3.x + p3.y) * (p3.x + p3.y))
return true;
// only stuck in this part
}
I can only get one part of the output:
This part:
Enter two integers for point 1: 0 0
Enter two integers for point 2: 0 1
Enter two integers for point 3: 2 0
The three points form a right-angled triangle.
Press any key to continue . . .
But not this part:
Enter two integers for point 1: 1 1
Enter two integers for point 2: 3 0
Enter two integers for point 3: 0 0
The three points form a right-angled triangle.
Press any key to continue . . .
Like it should say:
Enter two integers for point 1: 1 1
Enter two integers for point 2: 3 0
Enter two integers for point 3: 0 0
The three points don't form a right-angled triangle.
Press any key to continue . . .
I'm just having trouble with the boolean function, like isn't it just if it is true, output does form a right-angled triangle else false? I also tried return((p1.x + p1.y * p1.x + p1.y) + (p2.x + p2.y * p2.x + p2.y) == (p3.x + p3.y) * (p3.x + p3.y)); as that should output either true or false but it then just outputs only that the three points don't from a right-angled triangle. What am i missing here? Thanks in advance!