// Find Pythagorean triples
#include <iostream>
usingnamespace std;
int main()
{
constint LIMIT = 5; //for your second run change this to 500 IF YOU DARE!
int count = 0; // count # of triples found
longint hypotenuseSquared; // hypotenuse squared
longint sidesSquared; // sum of squares of sides
cout << "Side 1\tSide 2\tSide3" << endl;
() // Write a for-header for side1 ranging from 1 to LIMIT
{
for (int a = 1; a <= 5; a++) //STARTFORLOOP1
() // Write a for-header for side2 ranging from side1 to LIMIT
{
for (int b = 1; b <= 5; b++) //STARTFORLOOP2
()// Write a for-header or hypotenuse ranging from side2 to LIMIT
{
for (int c = 1; c <= 5; c++) //STARTFORLOOP3
// calculate hypotenuseSquared to be the hypotenuse squared
// calculate the sidesSquared to be the sum of each side squared
if (hypotenuseSquared == sidesSquared) //ie. is a Pythagorean triple
{
cout << side1 << '\t' << side2 << '\t' << hypotenuse << '\n';
count++; //count the triple
} //ENDIF
} //ENDinnerMOSTfor
} //ENDmiddleMOSTfor
} //ENDouterMOSTfor
//if LIMIT is 5......there will be 5*5*5=125 outputlines
//if LIMIT is 500...there will be 500*500*500=125,000,000 outputlines
cout << "A total of " << count << " triples were found." << endl;
return 0;
} // end main
I am trying to finish this code, and I am not entirely sure where to start... this code in particular confuses me, any help or direction would be nice.
everything in the code is what I have to work with. All I have other than that is it telling me to insert/modify 5 lines of code to make the program work.
for ( expr; expr; expr ) // comment
{
// other code
}
Therefore,
Line 17 should be in place of the parentheses on line 15.
Line 20 should be in place of the parentheses on line 18.
Line 23 should be in place of the parentheses on line 21.
What you have written on line 20 does not do what the instructions on line 18 say.
What you have written on line 23 does not do what the instructions on line 21 say.
Lines 25 and 26.
Seriously? The a, b, c are the side1, side2 and hypotenuse. Do you really claim that you don't know what square and sum are?