``````#include <iostream>
#include <cmath>

using namespace std;

int main()
{//begin main
double hypot(double,double);
double base;
double height;

cout<<"Program to compute the Hypotenuse of a given right triangle. \n"<<endl;
cout<<"Enter the base: \n"<< endl;
cin>>base;
cout<<"Enter the height: \n"<<endl;
cin>>height;
cout <<"The hypothenus of given triangle is " << hypot(base,height) <<endl;

system("pause");

return 0;
}//end main

double hypot(double base, double height)
{//begin function

double newb=pow(base,2.0);
double newh=pow(height,2.0);
double newa=newb+newh;
double hyp= pow(newa,.5);

return hyp;
}//end function``````

[Linker error] undefined reference to `hypot(double, double)'

Why is this happening?

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by ArkM

function declarations must be declared before main(), not inside.

``````int main()
{//begin main
double hypot(double,double);
....``````

should be

``````double hypot(double, double);

int main()
{
...``````

give that a try

~J

you are absolutely right, thanks :)

In actual fact it does not matter in C and C++ where a function prototype was placed if it stands before function using.
What a (bad) compiler are you using?

Apropos, why you compute simplest x*x as pow(x,2.0)?
You don't test input results. Try to enter (misprint) not-a-number...
Avoid using standard library names for your own functions. There is hypot function in <ccmath> (but it has extern "C" linkage).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.