Help with Pythagorean code

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  // Find Pythagorean triples
#include <iostream>
using namespace std;

int main()
{

	const int LIMIT = 5;                         //for your second run change this to 500 IF YOU DARE!
	int count = 0;                                 // count # of triples found
	long int hypotenuseSquared;            // hypotenuse squared
	long int 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.
Okay can you explain what are the requirements of the program? What is the input, output should be?
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.
The instructor has apparently written
1
2
3
4
() // comment
{
  // other code
}

with the intention that you modify it into
1
2
3
4
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?
Line 15, 18, 21:
Random () ???

Line 17, 20, 23:
Isn't the condition meant to be <= LIMIT?
Last edited on
Topic archived. No new replies allowed.