Pythagorean Theorum Code Help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Pythagorean Theorum Code Help

  1. #1
    Join Date
    Mar 2009
    Posts
    14

    Question 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. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    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. #3
    Join Date
    Mar 2009
    Posts
    14

    Question 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. #4
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,915

    Re: Pythagorean Theorum Code Help

    Quote Originally Posted by Frederick Lenz View Post
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center