-
March 31st, 2009, 01:03 AM
#1
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;
}
-
March 31st, 2009, 01:43 AM
#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.
-
March 31st, 2009, 08:05 PM
#3
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;
}
-
March 31st, 2009, 09:55 PM
#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.
There are only 10 types of people in the world:
Those who understand binary and those who do not.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|