### How can I make this program tell me all the pythagorean triples with no repeats?

I'm stuck on how I should make this program loop correctly to make it show all the triples of the pythagorean theorem that make perfect triangles. My instructor told me that my logic was correct but I know that my syntax is wrong. What should I change so that it shows all the triples up to 500 and display the count of them all?

 ``12345678910111213141516171819202122232425`` `````` #include #include using namespace std; int pythagorean(int a, int b, int c) int main(int argc, char *argv[]) { cout << "Pythagorean triples: " << endl; cout << pythagorean << endl; system("PAUSE"); return EXIT_SUCCESS; } int pythagorean (int a, int b, int c){ int total; for (int a=1;((a>=1)&&(a<500)); a++) for (int b=1;((b>=1)&&(b<500)); b++) for (int c=1;((c>=1)&&(c<500)); c++) if ((a*a) + (b * b)) = c * c) if ((a
Could you give us a prompt, please?
Here is the prompt:

When three integers a, b, and c satisfy the pythagorean equation, such as 3, 4, 5 do, the result is called a Pythagorean Triple. Create a program to list all of the Pythagorean Triples with integers of 500 or less. Also, give the total number of unique Pythagorean triples found by your program.

Try this out:

 ``1234567891011121314`` ``````#include using namespace std; int main() { for (int a = 1; a <= 500; ++a) for (int b = a; b <= 500; ++b) for (int c = b; c <= 500; ++c) if (a * a + b * b == c * c) cout << a << ' ' << b << ' ' << c << endl; return 0; }``````
I need to use a function in it and I fixed a few things which allowed it to run. However, when I run it now, the program repeats forever without stopping or using numbers that satisfy the pythagorean theorem. Here is what I have now:
 ``1234567891011121314151617181920212223242526272829`` ``````#include #include using namespace std; int pythagorean(); int main(int argc, char *argv[]) { cout << "Pythagorean triples: " << endl; int count = pythagorean(); cout << count << endl; system("PAUSE"); return EXIT_SUCCESS; } int pythagorean (){ int total = 0; for (int a=1; a<=500; a++){ for (int b=1; b<=500; b++){ for (int c=1; c<=500; c++){ if (a*a) + (b * b) == (c * c);{ if ((a
I'm not giving you all the answers, but I'm going to comment where all the obvious problems are.

 ``12345678910111213141516171819202122232425262728293031323334353637`` ``````#include #include using namespace std; int pythagorean(); int main(int argc, char *argv[]) { cout << "Pythagorean triples: " << endl; int count = pythagorean(); cout << count << endl; system("PAUSE"); return EXIT_SUCCESS; } int pythagorean () { int total = 0; for (int a=1; a<=500; a++) { for (int b=1; b<=500; b++) //if you change so that b is a + 1, you can get rid of an if statement. Do you see it? { for (int c=1; c<=500; c++) //this loop and the if following aren't completely necessary. You can use a and b to find c { if (a*a) + (b * b) == (c * c); //semicolon? Parentheses around the if? { if ((a
Last edited on
Alright, I tried to add your suggestions but am confused about what the return statement should be...
 ``12345678910111213141516171819202122232425262728293031`` ``````#include #include using namespace std; int pythagorean(); int main(int argc, char *argv[]) { cout << "Pythagorean triples: " << endl; int count = pythagorean(); cout << count << endl; system("PAUSE"); return EXIT_SUCCESS; } int pythagorean (){ int total = 0; for (int a=1; a<=500; a++) { for (int b= a + 1; b<=500; b++) { for (int c=1; c<=500; c++) { if ((a*a) + (b * b) == (c * c)) { cout << a << " " << b << " " << c << endl; total = total + 1; } } } } }``````
Wait, I tried to change some other stuff per Josue Molina's suggestion and now my program runs and hits a stop, but it doesn't have a count of how many there are and the first triple begins at 50, which I know is incorrect.
 ``123456789101112131415161718192021222324252627`` ``````int pythagorean(); int main(int argc, char *argv[]) { cout << "Pythagorean triples: " << endl; int count = pythagorean(); cout << count << endl; system("PAUSE"); return EXIT_SUCCESS; } int pythagorean (){ int total = 0; for (int a=1; a<=500; a++) { for (int b=a; b<=500; b++) { for (int c=b; c<=500; c++) { if ((a*a) + (b * b) == (c * c)) { cout << a << " " << b << " " << c << endl; total = total + 1; } } } } return 0; }``````
Check these out.
 ``123456789101112131415161718192021222324252627`` ``````int pythagorean(); int main(int argc, char *argv[]) { cout << "Pythagorean triples: " << endl; int count = pythagorean(); cout << count << endl; system("PAUSE"); return EXIT_SUCCESS; } int pythagorean (){ int total = 0; for (int a=1; a<=500; a++) { for (int b=a; b<=500; b++) //you should start b at a + 1 { for (int c=b; c<=500; c++) //yet again you should start at b + 1 { if ((a*a) + (b * b) == (c * c)) { cout << a << " " << b << " " << c << endl; //INDENTATIONS total = total + 1; //INDENTATIONS } //INDENTATIONS } } } return 0; //what is the return statement supposed to do? }``````

 ``1234567891011121314151617181920212223242526272829303132`` ``````#include #include using namespace std; int pythagorean(); int main(int argc, char *argv[]) { cout << "Pythagorean triples: " << endl; int count = pythagorean(); cout << "There are " << count << " pythagorean triples" << endl; system("PAUSE"); return EXIT_SUCCESS; } int pythagorean (){ int total = 0; for (int a=1; a<=500; a++) { for (int b= a + 1; b<=500; b++) { for (int c= b + 1; c<=500; c++) { if ((a*a) + (b * b) == (c * c)) { cout << a << " " << b << " " << c << " , "; total = total + 1; } } } } return total; )``````