I am attempting to write a function that determine the area of a triangle. I am not sure what I am doing wrong when trying to determine the area. The error message I am getting is "error-call of overloaded 'sqrt(int)is ambiguous.
Can you help me determine what is wrong??

#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;

void calc(int a,int b, int c,int s,float area)
{
    cout<<(a+b+c)<<"\n";
    cout<<(a+b+c)/2<<"\n";
    s=(a+b+c)/2;
    area=sqrt(s*(s-a)*(s-b)*(s-c));
    cout<<area;
}



int main()
{  
  int value1,value2,value3,value4,value5;
  
  cout<<"enter 3 intergers\n";
  cin>>value1>>value2>>value3;
  calc(value1,value2,value3,value4,value5);

                    
  system ("pause");                                  

  return 0;
}

Define "float s" in the calc function. The prototype of sqrt is most likely double sqrt (double).

#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;

void calc(int a,int b, int c,float s,float area)
{
    cout<<(a+b+c)<<"\n";
    cout<<(a+b+c)/2<<"\n";
    s=(a+b+c)/2;
    area=sqrt(s*(s-a)*(s-b)*(s-c));
    cout<<area;
}



int main()
{  
  int value1,value2,value3,value4,value5;
  
  cout<<"enter 3 intergers\n";
  cin>>value1>>value2>>value3;
  calc(value1,value2,value3,value4,value5);

                    
  system ("pause");                                  

  return 0;
}

Float s is the semiperimeter
Would this be the correct syntax then for the area?? I still get an error message. Does it need to be declared?? Thank you for your help!!

area=double sqrt(s*(s-a)*(s-b)*(s-c));

Float s is the semiperimeter

Can be, but also, from s=(a+b+c)/2 it also can be float, right?

area=double sqrt(s*(s-a)*(s-b)*(s-c));

Sqrt returns a double, or a float value; you don't need to convert the rezult, but the parameter of the sqrt:

area = sqrt(double(s*(s-a)*(s-b)*(s-c)));

Thanks that helped a bunch!! I got it now!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.