CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: Pythagorean Theorum Code Help

1. Junior Member
Join Date
Mar 2009
Posts
14

## Pythagorean Theorum Code Help

I made this code to find pythagorean theorums...
But it won't work right..
any help?

Code:
#include <iostream>
#include <string>
using namespace std;

int main ()
{
int a,b,c,d,e;
d = a * a+ b* b;
d = c * c;
cout << "Welcome to the LZ Pythagorean Theorem Finder" << endl << "To use this application, enter the values of variable A and B" << endl;
cout << "A = ";
cin >> a;
cout << "B = ";
cin >> b;
cout << "C = " << c << endl;

return 0;
}

2. ## Re: Pythagorean Theorum Code Help

Code:
```d = a * a+ b* b;
d = c * c;
cout << "Welcome to the LZ Pythagorean Theorem Finder" << endl << "To use this application, enter the values of variable A and B" << endl;```
You first make your calculation and then you ask for the numbers to calculate. Same as first eat your dinner and then you call the waiter to order the dinner.

3. Junior Member
Join Date
Mar 2009
Posts
14

## Re: Pythagorean Theorum Code Help

ok...i fixed that part
but it says that 'c' is unintialized
and i did initialize it

Code:
#include <iostream>
#include <string>
using namespace std;

int main ()
{
int a,b,c,d;
cout << "Welcome to the LZ Pythagorean Theorem Finder" << endl << "To use this application, enter the values of variable A and B" << endl;
cout << "A = ";
cin >> a;
cout << "B = ";
cin >> b;
d = a * a+ b* b;
d = c * c;
cout << "C = " << c << endl;

return 0;
}

4. ## Re: Pythagorean Theorum Code Help

Originally Posted by Frederick Lenz
ok...i fixed that part
but it says that 'c' is unintialized
and i did initialize it
WHERE?

This is a theorem:

The sum of the squares of the lengths of the legs of a right triangle ('a' and 'b' in this case) is equal to the square of the length of the hypotenuse (c).

So, why d? What is a purpose of it?

Try this:
Code:
```#include <iostream>
#include <string>
#include <conio.h>
#include <math.h>
using namespace std;

int main(int argc, char* argv[])
{
int a = 0, b = 0, c = 0; // this is initializing.
cout << "Welcome to the LZ Pythagorean Theorem Finder" << endl << "To use this application, enter the values of variable A and B" << endl;
cout << "A = ";
cin >> a;
cout << "B = ";
cin >> b;
c = pow(a, 2) + pow(b, 2);
cout << "C = " << c << endl;

getch(); // at least you can see the result

return 0;
}```
Besides, use CODE tags for code snippets.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•