pythagoream theorem

I am trying to find the hypotenuse of a right triangle with the user entering side a and side b. My program is having a problem in the function where it computes the hypotenuse. I think it might have to do with the sqrt because that's where I get an error and I've tried messing with it to no avail. Everything is right except for the above mentioned part so can you tell or show me how to get it right. Thanks.
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
 #include <iostream>
#include <cmath>
using namespace std;
//function prototype
double rightTriangle (double, double );

int main()
{
	double side_a, side_b, hypotenuse;

	//tells user what program will do
	cout<<"This program will return the value of the hypotenuse of a right triangle but\n";
	cout<<"you will need to enter the values for side a and side b of the right triangle\n";
	cout<<"in order to do so."<<endl<<endl;  
	//user enters values for side a and side b
	cout<<"Enter side a of the right triangle:"<<endl<<endl; 
	cin>>side_a;
	cout<<endl;
	cout<<"Enter side b of the right triangle:"<<endl<<endl;
	cin>>side_b;
	cout<<endl<<endl;

	hypotenuse = rightTriangle(side_a, side_b);

	system ("pause");
	return 0;
}

double rightTriange (double a, double b)
{
	double hypotenuse, sqrt, sides;

	sides = pow(a, 2.0)+pow(b, 2.0);
	hypotenuse = sqrt(sides);
	
	return hypotenuse; 


}
There are a few errors, but the main one is line 31. You should not attempt to define a variable named sqrt. The function sqrt() is already declared in the cmath header file.
Last edited on
In your function you declared three variables, hypotenuse, sqrt, sides. Then you try to use a function named sqrt(), on line 34. The compiler doesn't know if you want to use the variable sqrt or the function sqrt() on line 34. You don't want to declare that variable named sqrt, if you remove that declaration that should clear up the problem with sqrt().

Jim
Last edited on
Thanks. That seemed to clear up my problem but when I try to run the program I get the following:
6_2Num3.obj : error LNK2019: unresolved external symbol "double __cdecl rightTriangle(double,double)" (?rightTriangle@@YANNN@Z) referenced in function _main

and this too:
c:\users\owner\documents\visual studio 2010\Projects\6_2Num3\Debug\6_2Num3.exe : fatal error LNK1120: 1 unresolved externals
Line 29, there's a spelling mistake.
You wrote "rightTriange", without an 'L'.
Thanks, I appreciate all of your help. It's always the small stuff that gets in the way.
Topic archived. No new replies allowed.