This is a little exercise I'm having trouble with. To be quite frank, I don't really completely understand the problem.
I've asked my teacher for some help and he has given me the accompanying code as a guild.
(Pythagorean Triples) A right triangle can have sides that are all integers. The set of three intger values for the sides of a right triangle is called a Pythagorean triple. These three sides must satisfy the relationship that the sum of the squares of two of the sides is equal to the square of the hypotenuse. Find all Pythagorean triples for side1, side2 and hypotenuse all no larger than 100. Use a triple-nested for loop that tries all possibilities.
#include <iostream>
int main()
{
int count = 0;
long hyptSquared, sidesSquared;
for ( /* write header for side1 */ ) {
for ( /* write header for side2 */ ) {
for ( /* write header for hyptSquared */ ) {
/* calculate hyptSquared */
/* calculate the sum of the sides squared */
if ( hyptSquared == sidesSquared ) {
cout << side1 << "\t" << side2 << "\t"
<< hypt << "\n";
++count;
}
}
}
}
cout << "A total of " << count << " triples were found."
<< endl;
return 0;
}
I've gone through all my text books and tutorials on the net but I'm still stuck. PLEASE HELP!!!!! PLEASEEEEEEEEEEE
Guys I know this is asking a bit too much and I hate having
to ask but if I don't than I won't learn anything and I really want to learn. Thanks heaps