Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   strange problem of compiling (http://www.programmingforums.org/showthread.php?t=11310)

brad sue Sep 14th, 2006 4:32 AM

strange problem of compiling
 
Hi ,
I urgently need help . I make a program that compute the area of triangle.
When I run my program on my computer everything is OK. But when I run it on the school system I get this
compilation error:

ld:
Unresolved:
sqrt


My function is fixed ..I mean the argument types have been imposed.
Please can someone help me I just have few hours left.

:

#include<iostream>
#include<cmath>
#include<ctime>
#include<cstdlib>

using namespace std;

void compute_area(double&,double&,double,double,double);

int main()
{
    double area,perimeter;
    double a,b,c;

 
    cout<<"Enter length a: ";
    cin>>a;
    cout<<endl;

    cout<<"Enter length b: ";
    cin>>b;
    cout<<endl;

    cout<<"Enter length c: ";
    cin>>c;
    cout<<endl;
   
    compute_area(area,perimeter,a,b,c);
   
  return 0;
}//end main


void compute_area (double& area, double& perimeter, double a, double b,
double c)

    double s;
    //s=0;

    if( (a>(b+c))||(b>(a+c))||(c>(b+a)) )
    {  cout<<"bad combination!"<<endl;
        return;
      }

    else
    {
        s = (a + b + c)/ 2.0;
        area = sqrt (s*(s-a)*(s-b)*(s-c));
        perimeter=a+b+c;
        cout << "The area of a triangle with sides of length " << a
        << ", " << b << " and " << c << " is " << area <<
        " and its perimeter is "<<perimeter<< endl;
        return;
    } 
}

Thank you

The Dark Sep 14th, 2006 5:51 AM

You need the libm library, try adding -lm to the compile line

brad sue Sep 14th, 2006 9:27 AM

Quote:

Originally Posted by The Dark (Post 114110)
You need the libm library, try adding -lm to the compile line

YES!! Thank you The Dark


All times are GMT -5. The time now is 1:15 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC